2015-04-24 25 views
0

如何配置free-jqGrid(4.8)filterToolbar來搜索字段中的所有單詞?free-jqGrid filterToolbar包含一些單詞的客戶端搜索

數據

  1. 一二三
  2. 一二三四
  3. 一個四三

搜索詞

  • 「一四」,則返回第3行
  • 「四三」,返回2和3行
  • 「三合一」,返回行1和3
  • 「四」,返回2和3行

jqGrid的API

$("#list").jqGrid({ 
    datatype: "local", 
    colNames: ["Name"], 
    colModel: [{ 
     name: "name", 
     index: "name" 
    }], 
    caption: "Viz Test", 
    pager: '#pager', 
    search: true, 
    multiselect: true, 
    data: myData 
    }); 

    jQuery("#list").jqGrid('filterToolbar', { 
    searchOperators: true   
    }); 

回答

0

這是基於這個answer,需要free-jqgrid 4.8,看到演示的jsfiddle

colModel: [{ 
    name: "name", 
    index: "name", 
    searchoptions: { 
     sopt: ["sIn", "bw", "cn", "lt", "le", "gt", "ge", "in", "ni"] 
    } 
}], 


    customSortOperations: { 
    // the properties of customSortOperations defines new operations 
    // used in postData.filters.rules items as op peroperty 
    sIn: { 
     operand: "sIn", // will be displayed in searching Toolbar        
     text: "String In", // will be shown in Searching Dialog 
          // or operation menu in searching toolbar 
     filter: function (options) { 
      // called for filtering on the custom operation "sIn" 
      // 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 - values in the input field of searching toolbar 
      var fieldData = options.item[options.cmName]; 
      var words = options.searchValue.split(" ");     

      //loop thru each word in words array 
      $.each(words, function() { 
       //search for word in fielddata 
       var searchResults = fieldData.search(this) 
       //if not fouond 
       if (searchResults < 0) { 
        fieldData = "";       
       } 
      }); 

      return fieldData; 
     } 
    } 
+0

這使搜索不區分大小寫:var searchResults = fieldData.toLowerCase()。indexOf(this.toLowerCase()) –