免费的 jqGrid 允许定义自定义搜索/过滤操作customSortOperations
选项。默认情况下,相应的自定义比较操作将有两个操作数。一元运算应在中指定customUnaryOperations
另外的选项。该功能最初描述于维基文章 https://github.com/free-jqgrid/jqGrid/wiki/Custom-filtering-searching-Operation。人们可以在 stackoverflow 上找到一些使用该功能的示例。
定义的自定义比较/过滤运算符customSortOperations
需要包含在数组中相应列的定义中searchoptions.sopt
. The demo https://jsfiddle.net/OlegKi/jdzuwg2b/使用以下代码:
colModel: [
...
{ name: "name", align: "justify", width: 87, editrules: { required: true },
autoResizing: { minColWidth: 87 },
createColumnIndex: true,
searchoptions: {
generateDatalist: true,
sopt: [ "cn", "em", "nm", "in", "ni",
"teq", "tne",
"eq", "bw", "ew", "bn", "nc", "en" ],
clearSearch: true
} },
...
],
customUnaryOperations: ["em", "nm"],
customSortOperations: {
em: {
operand: "=''",
text: "is empty",
filter: function (options) {
var v = options.item[options.cmName];
if (v === undefined || v === null || v === "") {
return true;
}
}
},
nm: {
operand: "!=''",
text: "isn't empty",
filter: function (options) {
var v = options.item[options.cmName];
if (v !== undefined && v !== null && v !== "") {
return true;
}
}
},
teq: {
operand: "==",
text: "Turkish insensitive \"equal\"",
filter: function (options) {
var fieldData = String(options.item[options.cmName]).replace(/i/g,'İ').toUpperCase(),
searchValue = options.searchValue.replace(/i/g,'İ').toUpperCase();
return fieldData === searchValue;
}
},
tne: {
operand: "!=",
text: "Turkish insensitive \"not equal\"",
filter: function (options) {
var fieldData = String(options.item[options.cmName]).replace(/i/g,'İ').toUpperCase(),
searchValue = options.searchValue.replace(/i/g,'İ').toUpperCase();
return fieldData !== searchValue;
}
}
},
该代码定义了 4 个自定义操作:“em”、“nm”、“teq”、“tne”,其中“em”(“为空”)和“nm”(“非空”)是一元操作。我从旧答案中得到了代码:this one https://stackoverflow.com/a/29415927/315935 and 另一个 https://stackoverflow.com/a/41445578/315935.
The custom operations are available in searching toolbar and in the searching dialog:
![enter image description here](https://i.stack.imgur.com/8p1RJ.png)
我认为这就是您需要的功能。我建议您另外阅读另一个答案 https://stackoverflow.com/a/29676941/315935,这很接近您的要求。我认为简单修改代码就可以解决您的问题。