easyui combogrid 下拉框 智能输入
1. 后台代码
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using Contract.Domain;
using WebApp.Common;
namespace HraWeb.Common
{
/// <summary>
/// EntityJsonList 的摘要说明
/// </summary>
public class EntityJsonList : BasePage, IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
public PropertyInfo GetProperyInfo(string Name, PropertyInfo[] ps)
{
PropertyInfo p1 = null;
ps.ToList().ForEach(p =>
{
if (p.Name == Name)
{
p1 = p;
}
});
return p1;
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
switch (context.Request["_method"])
{
case "entity":
string entityType = context.Request["entityType"];
info = new Framework.QueryInfo();
info.QueryObject = entityType;
if (!string.IsNullOrEmpty(context.Request["where"]))
{
info.Where.Add("kk", " and " + context.Request["where"]);
}
var keyword = context.Request["keyword"] ?? string.Empty;
if (!string.IsNullOrEmpty(keyword))
{
Hashtable aa=new Hashtable();
aa.Add(context.Request["queryTextFild"].ToString()+"_LK",keyword);
info.AddParam(aa);
//info.Where.Add("kk2",string.Format(" and {0} like '%:{1}%'", context.Request["queryTextFild"],keyword));
}
info.PageSize = int.Parse(HttpContext.Current.Request["rows"]);
int pageIndex = int.Parse(HttpContext.Current.Request["page"]);
info.StartRecord = (pageIndex - 1) * info.PageSize;
info.TotalCount = 1;
if (!string.IsNullOrEmpty(context.Request.QueryString["queryFild"]))
{
string[] field = context.Request.QueryString["queryFild"].Split(new char[] { '|' });
foreach (string q in field)
{
info.AddParam(q, context.Request.QueryString["q"], string.Format(" and {0} like '%:{0}%'", q));
}
}
info = Dao.FindByQueryInfo(info);
Type type = null;
PropertyInfo[] ps = null;
if (info.List != null && info.List.Count > 0)
{
type = info.List[0].GetType();
ps = type.GetProperties();
}
bool idBoolean = false;
foreach (var b in info.List)
{
PropertyInfo idFieldInfo = GetProperyInfo(context.Request["idFild"], ps);
string IdFieldValue = Convert.ToString(idFieldInfo.GetValue(b, null));
if (!string.IsNullOrEmpty(context.Request["defaultValue"]))
{
if (IdFieldValue.Equals(context.Request["defaultValue"]))
{
idBoolean = true;
break;
}
}
}
//if (!string.IsNullOrEmpty(context.Request["defaultValue"]))
{
Framework.QueryInfo tmpInfo = new Framework.QueryInfo();
tmpInfo.QueryObject = entityType;
if (!string.IsNullOrEmpty(context.Request["idFild"]))
tmpInfo.AddParam(context.Request["idFild"], context.Request["defaultValue"]);
var list = Dao.FindList(tmpInfo);
foreach (object obj in list)
{
if (!idBoolean)
{
info.List.Add(obj);
}
}
}
DataGridJson d = new DataGridJson(info.TotalCount, info.List);
HttpContext.Current.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(d));
break;
case "dict":
var t = GetDictType(context.Request["dictType"]);
IList<SysDict> dictList= Holworth.Utility.Utility.ListToT<SysDict>(t);
//根据关键词使用linq进行二次过滤
var keyword2 = context.Request["keyword"] ?? string.Empty;
if (!string.IsNullOrEmpty(keyword2))
{
dictList = dictList.Where(x => x.Name.Contains(keyword2)).ToList();
}
string ss = Newtonsoft.Json.JsonConvert.SerializeObject(dictList);
context.Response.Write(ss);
break;
case "aa":
var ts = GetDictType(context.Request["dictType"]);
string sss = Newtonsoft.Json.JsonConvert.SerializeObject(ts);
context.Response.Write(sss);
break;
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
2.下拉框 实体前台代码
this.SetEntityCombo = function (obj, entityType, textField, columns, where, idFild, queryFild) {
var url = '/common/EntityJsonList.ashx?entityType=' + entityType + '&_method=entity&tmp=' + Math.random() + '&queryTextFild=' + textField;
if (where) {
url += "&where=" + where;
}
if (obj.val() != "") {
url += "&defaultValue=" + obj.val();
}
var id = 'Id';
if (idFild) {
id = idFild;
}
url += "&idFild=" + id;
// if (queryFild) {
// url += "&queryFild=" + queryFild;
// }
obj.combogrid({
panelWidth: 500,
idField: id,
textField: textField,
url: url,
method: 'get',
delay:1000,
pagination: true, //是否分页
rownumbers: true, //序号
pageSize: 10, //每页显示的记录条数,默认为10
pageList: [10], //可以设置每页记录条数的列表
columns: columns,
striped: true,
editable: true,
collapsible: false, //是否可折叠的
fit: true, //自动大小
keyHandler: {
up: function () { //【向上键】押下处理
//取得选中行
var selected = obj.combogrid('grid').datagrid('getSelected');
if (selected) {
//取得选中行的rowIndex
var index = obj.combogrid('grid').datagrid('getRowIndex', selected);
//向上移动到第一行为止
if (index > 0) {
obj.combogrid('grid').datagrid('selectRow', index - 1);
}
} else {
var rows = obj.combogrid('grid').datagrid('getRows');
obj.combogrid('grid').datagrid('selectRow', rows.length - 1);
}
},
down: function () { //【向下键】押下处理
//取得选中行
var selected = obj.combogrid('grid').datagrid('getSelected');
if (selected) {
//取得选中行的rowIndex
var index = obj.combogrid('grid').datagrid('getRowIndex', selected);
//向下移动到当页最后一行为止
if (index < obj.combogrid('grid').datagrid('getData').rows.length - 1) {
obj.combogrid('grid').datagrid('selectRow', index + 1);
}
} else {
obj.combogrid('grid').datagrid('selectRow', 0);
}
},
enter: function () { //【回车键】押下处理
obj.combogrid('hidePanel');
},
query: function (keyword) { //【动态搜索】处理
//设置查询参数
var queryParams = obj.combogrid("grid").datagrid('options').queryParams;
queryParams.keyword = keyword;
obj.combogrid("grid").datagrid('options').queryParams = queryParams;
//重新加载
obj.combogrid("grid").datagrid("reload");
obj.combogrid("setValue", keyword);
}
},
mode: 'remote',
fitColumns: true
});
}
数据字典下拉框前台代码
this.SetDict = function (obj, dicType) {
obj.combogrid({
panelWidth: 250,
idField: 'Code',
textField: 'Name',
url: '/Common/EntityJsonList.ashx?_method=dict&dictType=' + dicType + "&tmp=" + Math.random()+'&queryTextFild=Name',
method: 'get',
delay: 1000,
columns: [[
{ field: 'Name', title: '名称', width: 100 },
{ field: 'Code', title: '编码', width: 100 }
]],
striped: true,
editable: true,
collapsible: false, //是否可折叠的
fit: true, //自动大小
keyHandler: {
up: function () { //【向上键】押下处理
//取得选中行
var selected = obj.combogrid('grid').datagrid('getSelected');
if (selected) {
//取得选中行的rowIndex
var index = obj.combogrid('grid').datagrid('getRowIndex', selected);
//向上移动到第一行为止
if (index > 0) {
obj.combogrid('grid').datagrid('selectRow', index - 1);
}
} else {
var rows = obj.combogrid('grid').datagrid('getRows');
obj.combogrid('grid').datagrid('selectRow', rows.length - 1);
}
},
down: function () { //【向下键】押下处理
//取得选中行
var selected = obj.combogrid('grid').datagrid('getSelected');
if (selected) {
//取得选中行的rowIndex
var index = obj.combogrid('grid').datagrid('getRowIndex', selected);
//向下移动到当页最后一行为止
if (index < obj.combogrid('grid').datagrid('getData').rows.length - 1) {
obj.combogrid('grid').datagrid('selectRow', index + 1);
}
} else {
obj.combogrid('grid').datagrid('selectRow', 0);
}
},
enter: function () { //【回车键】押下处理
obj.combogrid('hidePanel');
},
query: function (keyword) { //【动态搜索】处理
//设置查询参数
var queryParams = obj.combogrid("grid").datagrid('options').queryParams;
queryParams.keyword = keyword;
obj.combogrid("grid").datagrid('options').queryParams = queryParams;
//重新加载
obj.combogrid("grid").datagrid("reload");
obj.combogrid("setValue", keyword);
}
},
mode: 'remote',
fitColumns: true
});
}
easyui combogrid 下拉框 智能输入的更多相关文章
- easyui combogrid下拉表格的分页/按键/动态搜索
作者:xfl4629712 < easyui combogrid下拉表格的分页/按键/动态搜索 > 需求: 1.下拉框下拉时出现表格: 2.表格带分页功能: 3.可以使用向上键.向下 ...
- 关于easyui combobox下拉框实现多选框的实现
好长时间没有更博了,一是因为最近真的比较忙,二是因为自己是真的偷懒了,哈哈 好啦,这篇博客主要是总结一些关于easyui combobox下拉框实现多选框的实现,包括前台界面的展示,和后台对数据的获取 ...
- easyui combobox下拉框复制后再禁用,点击不会出现下拉框
easyui combobox下拉框禁用,点击不会出现下拉框 需要做到,在给easyui combobox赋值后,再禁用easyui combobox 解决办法: $("#time-sele ...
- easyui combotree下拉框多选赋值
发现jquery.easyui.min.js 1.3.4版本的用setValues给多选下拉框赋值不成功,只能用1.3.1版本的 Html代码: <input id="ProductL ...
- JS为Select下拉框添加输入功能
JavaScript使用parentNode.nextSibling.value实现的本功能,实际上你会发现网页上有两个控件元素,一个是Select,一个是input,使用CSS将input覆盖于se ...
- easyui combobox下拉框文字超出宽度有横向滚轮
//下拉框显示横向滚轮 $(".combo").mouseenter(function(){ $(this).prev().combobox("showPanel&quo ...
- easyUI combobox下拉框很长,easyUI combobox下拉框如何显示滚动条的解决方法
如下图,combobox下拉框里内容很多时,会导致下拉框很长,很不美观. 如何使得combobox下拉框显示滚动条 方法:把属性panelHeight:"auto"注释掉即可. $ ...
- easyui combobox下拉框中显示大于号小于号的问题
前两天同事做了个功能,通过勾选下拉框里的值进行列表查询,结果下拉框里的值是“0<t<=2”.“2<t<=5”.“t>5”这样的. combobox是用脚本渲染出来的,里面 ...
- easyui combo下拉框多选框
按照自己的方式,先晒下效果图: 选一个值,那么就在input里面显示一个,去掉勾选,那么input就会少一个 其实做法很简单,今天就是快下班了,闲着没事加篇博客而已,下面带上代码. 1.页面的展示,i ...
随机推荐
- FPGA与图像处理
用FPGA做图像处理最关键的一点优势就是:FPGA能进行实时流水线运算,能达到最高的实时性.因此在一些对实时性要求非常高的应用领域,做图像处理基本就只能用FPGA.例如在一些分选设备中图像处理基本上用 ...
- Java运算符,关系运算符
关系运算符介绍 下表为Java支持的关系运算符 表格中的实例整数变量A的值为10,变量B的值为20: 运算符 描述 例子 == 检查如果两个操作数的值是否相等,如果相等则条件为真. (A == B)为 ...
- [转][Java]Jsp入门
<% response.getOutputStream().write("123".getBytes()); %> 新建一个 Web Project 项目,jsp 文件 ...
- node的socket.io的之基本使用方法.
使用socket.io的使用创建一个socket.io服务器即可.但是该服务器依赖于一个已经创建的http服务器. 在http服务器运行之后,使用listen方法为该http服务器附加一个socket ...
- java基础循环
一. while循环 示例1:.循环打印1到10之间的值 public class Test1 { public static void main(String[] args) { int i=1;/ ...
- nginx+php产生大量TIME_WAIT连接解决办法
问题:当启动nginx和php-fpm时,使用netstat -tunap查看到大量TIME_WAIT连接 由于不知道原因,害怕是受到攻击,马上killall nginx 和php-fpm 会不会是8 ...
- Julia - 函数的参数传递
不定参数 不定参数的函数也称变参函数 函数的参数可以被定义成任意个 可以在最后一个参数后紧跟省略号“...”来定义变参函数 julia> bar(x, y, z...) = (x, y, z) ...
- Dev GridControl 选择行及绑定/获取List对象
GridControl绑定List对象一般是为了获取焦点行时直接获得该行代表的List对象,或者为了实现嵌套表格,对第一中情况,起始不用绑定List,绑定DataTable也可以实现获取对应List对 ...
- ubuntu安装Theano+cuda
由于学习需要用到GPU加速机器学习算法,需要安装theano+cuda. 开源库的一大问题就是:难安装. 为了搞好这个配置,我是前前后后花了3天,重装了3次ubuntu重装了5次驱动才搞定. 故发此贴 ...
- 关于jquery中的parent的认定
<li><label class='checkbox inline'><input type='checkbox' name='type[]' value='{$item ...