我有一个带有filterToolbar的jqGrid。在我的其中一列中,我想搜索“过滤器测试”的地方,调用了我的自定义函数,显然返回的是,则返回true,否则返回false。
jqGrid可以这样做吗?
答案 0 :(得分:1)
使用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;
}
}
},