如何使 "jqGrid toolbar search" 在任何情况下都搜索 at,而不仅仅是开头

How to make the "jqGrid toolbar search" search for the at in any occurrence, not just the beginning

我实现了一个启用了工具栏搜索的 jqGrid。 问题是搜索像“%search_criteria”一样工作(只从头开始匹配) 但我需要它像 '%search_criteria%'(列值中的任何出现)。

例如:网格有一列 "Class",其值:Math-101 和 Math-102 如果搜索:“101”==> 得到零个匹配项。 我必须搜索整个单词 "Math-101".

我看到了一个示例,它按我的意愿工作,它与我的 Grid 完全没有区别,我不知道它在下面的示例中如何工作,而不是在我的示例中工作! 例如:http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridWithSearchingToolbar.htm

我的网格:

var data = [[1, "Math-101", "OC", "INTEL", "09-02-15", "09-30-15", "A", 120, "General", 200]]
$("#grid").jqGrid({
                    datatype: "local",
                    height: 200,
                    colNames:['#','Class','Loc','Type','Start Dt','End Dt','Section','Dur','Gen/Priv','Fee'],
                    colModel: [
                    {name: 'scheduleID',    index: 'scheduleID',  width: 30},
                    {name: 'className',     index: 'className',   width: 60},
                    {name: 'Location',      index: 'Location',    width: 60},
                    {name: 'classType',     index: 'classType',   width: 60},
                    {name: 'startDt',       index: 'startDt',     width: 60,  sorttype: "date",
                    searchoptions:{dataInit:function(el){$(el).datepicker({dateFormat:'yy-mm-dd'});} }},
                    {name: 'endDt',         index: 'endDt',       width: 60,  sorttype: "date",
                    searchoptions:{dataInit:function(el){$(el).datepicker({dateFormat:'yy-mm-dd'});} }},
                    {name: 'section',       index: 'section',     width: 60},
                    {name: 'duration',      index: 'duration',    width: 60},
                    {name: 'scheduleType',  index: 'scheduleType',width: 60},
                    {name: 'Fee',           index: 'Fee',         width: 60, formatter:'number', align:'right'}
                    ],
                    pager: '#pager',
                    rowNum: 10,
                    rowList: [10, 20, 30],
                    rownumbers: true,
                    sortname: "Class",
                    sortorder: "desc",
                    viewrecords: true,
                    gridview: true,
                    ignoreCase: true,
                    autoencode: true,
                    autowidth: true,
                    ExpandColClick: true,
                    caption: "Schedule List"
            });
                    var names = ['scheduleID', 'className', 'Location', 'classType', 'startDt', 'endDt', 'Section', 'duration', 'scheduleType', 'Fee', 'CEU', 'Status', 'IFee', 'TCost', 'FCost', 'MCost', 'OMCost'];
                    var mydata = [];
                    for (var i = 0; i < data.length; i++) {
            mydata[i] = {};
                    for (var j = 0; j < data[i].length; j++) {
            mydata[i][names[j]] = data[i][j];
            }
            }

            for (var i = 0; i <= mydata.length; i++) {
            $("#grid").jqGrid('addRowData', i + 1, mydata[i]);
            }

            
        $("#grid").jqGrid('filterToolbar', { stringResult: true, searchOperators: false, searchOnEnter: false, autosearch: true, defaulySearch: "cn" });
        

感谢您的帮助。

您应该将 defaulySearch: "cn" 替换为 defaultSearch: "cn"。它应该解决主要的搜索问题。您应该考虑使用 jqGrid 的 ignoreCase: true 选项来强制 jqGrid 使用不区分大小写的搜索。

此外,我强烈建议您不要在循环中使用 addRowData 来填充 jqGrid。相反,您应该在 创建网格之前移动填充网格数据的代码 mydata 并仅使用选项 data: mydata。它将创建具有填充数据的数据。将显示排序数据的第一页。 jqGrid 会在数据显示之前对其进行排序。

小补充说明:您应该将 sortname: "Class" 修改为 sortname: "className"。我建议您从 colModel 中删除所有 index 值。您可以考虑使用 cmTemplate: { width: 60 } 选项(参见 the answer) which changes the default value of the property width in colModel from 150 to 60. After that you can remove all width: 60 from colModel. I recommend you to add sorttype: 'number' to the column which uses formatter:'number'. It will fix sorting in the column. You can consider to define template for two columns which contains dates (see the answer)。