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

时间:2017-12-18 11:44:04

标签: javascript jquery jqgrid

jQuery网格顶部有过滤选项,我可以在其中输入“text”或实现下拉列表。

我想做的是允许使用可配置选项搜索int列,例如“tax”,例如'< 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",
       			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>

1 个答案:

答案 0 :(得分:1)

如果我正确理解了您的需求,则应将searchOperators: true添加到filterToolbar的选项中,并在sopt searchoptions属性中指定更多作为一个比较操作。例如,

{name: "tax", width: 80, align: "right", sorttype: "float",
   searchoptions: {
     sopt: ["le", "lt", "gt", "ge", "eq", "ne"]
   }
}

请参阅https://jsfiddle.net/z6rfw3cp/