如何在jQgrid中实现搜索,以便用户可以通过<,>或<=, > =?进行过滤。

jQuery网格顶部有过滤器选项,我可以在其中输入“文本”或实现下拉列表。如何在jQgrid中实现搜索,以便用户可以通过<,>或<=, > =?进行过滤。

我想不过的事情,是允许使用搜索int列,如“税”与配置选项,如“< 10”,其中既有“<”和“10”应该是用户的参数。这将是一种客户搜索。

我不希望在另外一种模式下进行此项搜索,但作为最后一招也是可以的。

这是我到目前为止。

var mydata = [  

{id:"1",invdate:"2010-05-24",name:"test",note:"note",tax:"10.00",total:"2111.00"} ,

{id:"2",invdate:"2010-05-25",name:"test2",note:"note2",tax:"20.00",total:"320.00"},

{id:"3",invdate:"2007-09-01",name:"test3",note:"note3",tax:"30.00",total:"430.00"},

{id:"4",invdate:"2007-10-04",name:"blah",note:"stuff",tax:"10.00",total:"210.00"},

];

grid = jQuery("#list");

grid.jqGrid({

data: mydata,

datatype: "local",

height: 150,

rowNum: 10,

rowList: [10,20,30],

colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],

colModel:[

{name:'id',index:'id', width:60, sorttype:"int", search: true},

{name:'invdate',index:'invdate', width:90, sorttype:"date", formatter:"date"},

{name:'name',index:'name', width:100},

{name:'amount',index:'amount', width:80, align:"right",sorttype:"float", formatter:"number"},

{name:'tax',index:'tax', width:80, align:"right",sorttype:"float",

\t \t \t searchoptions: {sopt:['gt']}

},

{name:'total',index:'total', width:80,align:"right",sorttype:"float"},

{name:'note',index:'note', width:150, sortable:false}

],

pager: "#pager",

viewrecords: true,

autowidth: true,

height: 'auto',

caption: "Test Grid"

});

jQuery("#list").jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch: "cn" });

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css">  

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.2/css/ui.jqgrid.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.2/jquery.jqgrid.min.js"></script>

<table id="list"></table>

<div id="pager"></div>

回答:

如果我理解正确,你需要什么,你应该添加searchOperators: truefilterToolbar选项和一个在searchoptionssopt属性比较操作指定更多。例如,

{name: "tax", width: 80, align: "right", sorttype: "float", 

searchoptions: {

sopt: ["le", "lt", "gt", "ge", "eq", "ne"]

}

}

见https://jsfiddle.net/z6rfw3cp/

以上是 如何在jQgrid中实现搜索,以便用户可以通过&lt;,&gt;或&lt;=, &gt; =?进行过滤。 的全部内容, 来源链接: utcz.com/qa/263062.html

回到顶部