免费的 jqGrid 允许定义关于 customSortOperations 选项的自定义搜索/过滤操作。默认情况下,相应的自定义比较操作将有两个操作数。应在customUnaryOperations 选项中另外指定一元操作。该功能最初在the wiki article 中描述。您可以在 stackoverflow 上找到一些使用该功能的示例。
customSortOperations 中定义的自定义比较/过滤运算符需要包含在数组searchoptions.sopt 中相应列的定义中。 The demo 使用以下代码:
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 和 another one。
自定义操作在搜索工具栏和搜索对话框中可用:
我认为这是您需要的功能。我建议您另外阅读another answer,这接近您的要求。我认为对代码进行简单的修改可以解决您的问题。