我有一个带有过滤器工具栏的 jqGrid。在我的一个专栏中,我想在“过滤器测试”的位置进行搜索,调用我的自定义函数,并且显然返回 true 表示是,它通过了 false 表示否。
jqGrid 可以做到这一点吗?如果可以,怎么做?
最佳答案
使用 jqGrid 的免费分支,您可以使用以下内容
在您的 colModel 中添加值 searchoptions,如下所示:
{name:'FIELD',width:120,searchoptions:{ sopt: ["cust"] },label:"Field name"}
然后将以下属性添加到jqGrid
customSortOperations: {
// the properties of customSortOperations defines new operations
// used in postData.filters.rules items as op peroperty
cust:{
operand: "Custom",// will be displayed in searching Toolbar for example
text: "Custom", // will be shown in Searching Dialog or operation menu in searching toolbar
filter: function (options) {
// The method will be called in case of filtering on the custom operation "cust"
// All parameters of the callback are properties of the only options parameter.
// It has the following properties:
// item - the item of data (exacly like in mydata array)
// cmName - the name of the field by which need be filtered
// searchValue - the filtered value typed in the input field of the searching toolbar
// Get cell data as lowercase
var fieldData = options.item[options.cmName].toLowerCase(),
// Get search terms all in lowercase
terms = $.map(options.searchValue.split(" "), function(val){ return $.trim(val).toLocaleLowerCase(); }),
// A match found
match = false;
// Loop through terms and see if there is a match in the row cell data
$.each(terms, function(i,v)
{
if(fieldData.indexOf(v) != -1)
{
match = true;
// Quit the each loop
return false;
}
});
return match;
}
}
},
关于javascript - jqGrid如何应用自定义过滤/搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54280291/