jqGrid的搜索框下拉

 

当需要在jqGrid的搜索框里配置搜索条件时,如下拉,日期等,代码如下:

1      datePick = function(elem)
2      {
3          jQuery(elem).datepicker();
4 }
复制代码
 1         colNames  : [ "OP_ID", "OP_Module", "OP_Type", "OP_Content", "Operator", "OperatorType", "OP_Time", "OP_IP"],
 2         colModel  : [{name:'op_id', index:'op_id', width:100, align:'center', editable:false, search:false},
 3                      {name:'op_module', index:'op_module', width:110, align:'center', search:true, editable:false,
 4                          stype:'select', searchoptions: {dataUrl:'./select/module', sopt:['eq', 'ne']}},
 5                      {name:'op_type', index:'op_type', width:100, align:'center', search:true, editable:false,
 6                          stype:'select', searchoptions: {dataUrl:'./select/type', sopt:['eq', 'ne']}},
 7                      {name:'op_content', index:'op_content',  width:250, align:'center', editable:false, sortable:false,
 8                          stype:'text', searchoptions: {sopt:['bw', 'bn', 'ew', 'en','cn', 'nc']}},
 9                      {name:'op_by', index:'op_by', width:100, align:'center', search:true, editable:false},
10                      {name:'operator_type', index:'operator_type', width:130, search:true, align:'center', editable:false,
11                          stype:'select', searchoptions: {dataUrl:'./select/operator_type', sopt:['eq', 'ne']}},
12                      {name:'op_at', index:'op_at', width:170, align:'center', search:true, editable:false, 
13                          stype:'text', searchoptions: {dataInit:datePick, attr:{title:'Select Date'}, sopt:['cn', 'nc', 'in', 'ni']}, formatter:'date', formatoptions:{srcformat: 'Y-m-d H:i:s', newformat: 'm/d/Y  H:i:s'}},
14                      {name:'op_ip', index:'op_ip', width:100, align:'center', search:true, editable:false}
15                     ],
复制代码

 

其中,colModel的属性的stype有“text”和“select”两种,需要下拉选项时,则选择“select”;同时,searchoptions也进行设置,dataUrl为请求路由,路由返回的数据是

<select><option>1</option></select>的格式;重要的是需设定:ajaxSelectOptions: {type: "GET"} ,其中type可以是Post,这样你的搜索才能返回数据。

复制代码
1     jQuery(grid_selector).jqGrid({        
2         url                : "./show_log",
3         datatype           : "json",
4         mtype             : "post",
5         height            : 370,
6         width             : 1150,
7         ajaxSelectOptions : {type: "GET"} ,
复制代码

 

而想显示日期选择框时,stype设定为“type”,searchoptions: {dataInit:datePick, attr:{title:'Select Date'}, sopt:['cn', 'nc', 'in', 'ni']},

formatter:'date', formatoptions:{srcformat: 'Y-m-d H:i:s', newformat: 'm/d/Y H:i:s'}}。其中,formatoptions可以自己设置需要的格式。

 

op=
eq=等于
ne=不等
lt=小于
le=小于等于
gt=大于
ge=大于等于
bw=开始于
bn=不开始于
in=在内
ni=不在内
ew=结束于
en=不结束于
cn=包含
nc=不包含 

转载于:https://www.cnblogs.com/GoCircle/p/7650813.html

要封装 jqGrid 表头条件搜索,你可以按照以下步骤进行: 1. 在 HTML 页面中添加一个表格,并为其指定一个唯一的 ID。 2. 在 JavaScript 中使用 jqGrid 插件对该表格进行初始化,并设置表头条件搜索的相关参数,例如: ``` $("#grid").jqGrid({ url: "data.json", datatype: "json", colModel: [ { name: "id", index: "id", width: 55 }, { name: "name", index: "name", width: 90 }, { name: "category", index: "category", width: 80, stype: "select", searchoptions: { value: ":All;1:Category 1;2:Category 2" } }, { name: "price", index: "price", width: 80, align: "right", formatter: "currency", formatoptions: { decimalSeparator: ".", thousandsSeparator: ",", decimalPlaces: 2, prefix: "$ " }, searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] } }, ], rowNum: 10, rowList: [10, 20, 30], pager: "#pager", sortname: "id", viewrecords: true, sortorder: "desc", caption: "jqGrid Example", height: "auto", autowidth: true, search: true, searchOnEnter: false, searchOperators: true, searchToolbar: true, }); ``` 在上面的代码中,`colModel` 数组中的每个元素表示表格中的一列,其中 `stype` 属性用于指定该列的搜索类型,例如 `select` 表示下拉列表框,`text` 表示文本框,`date` 表示日期选择框等。`searchoptions` 属性用于设置该列的搜索选项,例如 `value` 属性可以设置下拉列表框中的选项,`sopt` 属性可以设置该列支持的搜索操作符。 3. 在 HTML 页面中添加一个搜索框,并为其指定一个唯一的 ID。 4. 在 JavaScript 中使用 jqGrid 插件的 `filterToolbar` 方法对搜索框进行初始化,并指定要搜索的表格的 ID,例如: ``` $("#grid").jqGrid("filterToolbar", { searchOnEnter: false, searchOperators: true }); ``` 在上面的代码中,`searchOnEnter` 属性表示是否在按下回车键时触发搜索操作,`searchOperators` 属性表示是否显示搜索操作符列表。 通过以上步骤,你就可以封装 jqGrid 表头条件搜索了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值