0

How can I configure free-jqGrid (4.8) filterToolbar to search all word within a field?

Data

  1. one two three
  2. two three four
  3. one four three

Search Words

  • "one four" , returns row 3
  • "four three" , returns rows 2 and 3
  • "one three" , returns rows 1 and 3
  • "four" , returns rows 2 and 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        
    });
shA.t
  • 16,580
  • 5
  • 54
  • 111
Barry MSIH
  • 3,525
  • 5
  • 32
  • 53

1 Answers1

0

This is based on this answer and requires free-jqgrid 4.8 and see demo on 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;
        }
    }
Community
  • 1
  • 1
Barry MSIH
  • 3,525
  • 5
  • 32
  • 53
  • this makes the search case insensitive: var searchResults = fieldData.toLowerCase().indexOf(this.toLowerCase()) – Barry MSIH Apr 25 '15 at 11:26