Reputation: 1392
The jQuery grid has filter options on top, where I can either enter "text" or implement a dropdown list.
What I wish to do however, is allow the use to search an int column such as "tax" with configurable options such as '<10' where both '<' and '10' should be user parameters. This would be a sort of customer search.
I prefer not to have this search in an additional modal, but as a last resort that is also ok.
Here is what I have so far.
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>
Upvotes: 0
Views: 291
Reputation: 221997
If I correctly understand what you need, you should add searchOperators: true
to the options of filterToolbar
and to specify more as one compare operation in sopt
property of searchoptions
. For example,
{name: "tax", width: 80, align: "right", sorttype: "float",
searchoptions: {
sopt: ["le", "lt", "gt", "ge", "eq", "ne"]
}
}
See https://jsfiddle.net/z6rfw3cp/
Upvotes: 1