如何在jqGrid中禁用seleted列的搜索操作?

我有一个带列filter的五列(2个整数,3个字符串列)网格。 我希望搜索操作的整数值(更大,更小,相等)工作正常,我不希望搜索字符串列操作。

我正在使用后端搜索。

我想要的是附上模型图像,如下所示

我想要搜索,但我不希望搜索操作的字符串有列

如何删除所选列中的搜索操作。 请帮我。

在此处输入图像描述

jQuery("#list451").jqGrid({ url: 'localset.php', datatype: "json", height: 255, width: 600, colNames: ['Index', 'Name', 'Code', 'N Name', 'C Name'], colModel: [{ name: 'item_id', index: 'item_id', width: 65, sorttype: 'integer', searchoptions: { sopt: ['eq', 'ne', 'le', 'lt', 'gt', 'ge'] } }, { name: 'name', index: 'name', width: 150, sorttype: 'string', searchoptions: { sopt: [] } }, { name: 'code', index: 'code', width: 150, sorttype: 'string', searchoptions: { sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en'] } }, { name: 'n_name', index: 'n_name', width: 150, sorttype: 'string', searchoptions: { sopt: [] } }, { name: 'c_name', index: 'c_name', width: 150, sorttype: 'string', searchoptions: { sopt: [] } }, rowNum: 50, rowTotal: 200, rowList: [20, 30, 50], loadonce: true, mtype: "GET", rownumbers: true, rownumWidth: 40, gridview: true, pager: '#pager451', sortname: 'item_id', viewrecords: true, sortorder: "asc", caption: "Loading data from server at once" }); jQuery("#list451").jqGrid('filterToolbar', { searchOperators: true }); 

我发现你的问题非常有趣,所以我准备了演示如何解决问题的演示 。 结果如下图所示:

在此处输入图像描述

当前版本的jqGrid支持clearSearch ,可以为每个特定列定义,但它不支持列特定的searchOperators选项。 searchOperators只有searchOperators选项应用于所有列。

该演示调用normalizeFilterToolbar函数,该函数使用所有列的灼热操作隐藏搜索输入的部分,其中在列定义中使用新的searchOperators: false选项或指定了一个操作(例如,在searchoptions中未定义searchoptions或如果没有定义任何搜索searchoptions )。 相应的代码看起来

 var $grid = $("#list"), // the grid normalizeFilterToolbar = function () { var $self = this, colModel = $self.jqGrid("getGridParam", "colModel"), $searchToolbarColumns = $self.closest(".ui-jqgrid-view") .find(">.ui-jqgrid-hdiv .ui-jqgrid-htable .ui-search-toolbar>.ui-th-column"), cCol = colModel.length, iCol, cm; for (iCol = 0; iCol < cCol; iCol++) { cm = colModel[iCol]; if (cm.searchoptions == null || ((cm.searchoptions.sopt == null || cm.searchoptions.sopt.length === 1) && cm.searchoptions.searchOperators !== true) || (cm.searchoptions.searchOperators === false)) { // hide the searching operation for the column $($searchToolbarColumns[iCol]).find(">div>.ui-search-table .ui-search-oper").hide(); } } }; // create the grid $grid.jqGrid({ // ... the options }); $grid.jqGrid("filterToolbar", {searchOperators: true, defaultSearch: "cn"}); normalizeFilterToolbar.call($grid); 

colModel中使用search:false表示您不需要搜索的列。

UPDATE
您可以通过替换搜索选项来自定义网格中的搜索选项使用搜索规则

 searchrules:{custom:true, custom_func: fnc_myStringCheck }, search:true } 

确保stype是文本(虽然它是默认值)和fnc_myStringCheck用于自定义方法。 希望这可以帮助。