gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:50:45 25 4
gpt4 key购买 nike

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

但是,我想做的是允许使用可配置选项(例如“<10”)搜索 int 列(例如“tax”),其中“<”和“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>

最佳答案

如果我正确理解你需要什么,你应该添加 searchOperators: truefilterToolbar 的选项并将多个指定为 sopt 中的一个比较操作searchoptions的属性(property)。例如,

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

参见https://jsfiddle.net/z6rfw3cp/

关于javascript - 如何在jQgrid中实现搜索以便用户可以通过<,>或<=,>=进行过滤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47867787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com