JQGrid Toolbar Searching: search for multiple words for a column

匿名 (未验证) 提交于 2019-12-03 02:11:02

问题:

I use the Toolbar Searching. Can you do a search for multiple words for a column? The delimiter is a space and the search should be done using the Like operator. As a result, the search should return all rows that have met all the words in the search string, no matter in what order they go in a field of row. For example there is a column "Product Name", I want to find all rows that have product name contains the word "lever" and contains the word "left."

回答1:

An interesting question!

I created the demo which demonstrate how to implement multi-word searching:

The corresponding code is:

$grid.jqGrid('filterToolbar', {     stringResult: true,     defaultSearch: "cn",     beforeSearch: function () {         modifySearchingFilter.call(this, ' ');     } }); 

where modifySearchingFilter I defined in the way:

var modifySearchingFilter = function (separator) {         var i, l, rules, rule, parts, j, group, str,             filters = $.parseJSON(this.p.postData.filters);         if (filters && typeof filters.rules !== 'undefined' && filters.rules.length > 0) {             rules = filters.rules;             for (i = 0; i  1) {                         if (typeof filters.groups === 'undefined') {                             filters.groups = [];                         }                         group = {                             groupOp: 'OR',                             groups: [],                             rules: []                         };                         filters.groups.push(group);                         for (j = 0, l = parts.length; j 

UPDATE: Free jqGrid supports Custom filtering searching Operation, which makes very easy the implementation of such scenarios like above.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!