如何禁用jqGrid中的选定列的搜索操作? [英] How to disable search opertion for seleted column in jqGrid?
问题描述
我有一个带有列过滤器的5列(2整数,3个String列)网格.我要搜索整数值(更大,更少,等于)的操作正常,我不希望对字符串列进行搜索.
I have a five column(2 integer,3 String column) grid with column filter. i want search operations for integer values(greater,less,equal) its working fine, i don't want search operations for string column.
我正在使用后端搜索.
下面附有期望的型号图片,请找到它
What am expecting is attached the model image as below please find it
我要搜索,但我不希望对具有列的String进行搜索
如何删除所选列中的搜索操作.请帮助我.
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
});
推荐答案
I find your question very interesting and so I prepared the demo which shows how the problem can be solved. The results looks like on the picture below:
jqGrid的当前版本支持clearSearch
,可以为每个特定的列定义它,但是不支持特定于列的searchOperators
选项.只有filterToolbar
的searchOperators
选项适用于所有列.
The current version of jqGrid support clearSearch
which can be defined for every specific column, but it didn't support column specific searchOperators
option. There are only searchOperators
option of filterToolbar
applied to all columns.
演示程序调用normalizeFilterToolbar
函数,该函数使用所有列的灼热操作隐藏搜索输入的一部分,其中在列定义中使用了新的searchOperators: false
选项,或者仅使用了一个操作指定(例如,在searchoptions
中没有定义sopt
,或者如果根本没有定义searchoptions
).相应的代码看起来
The demo calls normalizeFilterToolbar
function which hide the part of searching input with the searing operation for all columns where either new searchOperators: false
option are used in the column definition or where only one operation are specified (for example is no sopt
are defined in searchoptions
or if no searchoptions
at all are defined). The corresponding code looks
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);
这篇关于如何禁用jqGrid中的选定列的搜索操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!