neoswf
neoswf

Reputation: 4760

SlickGrid- Need of insensitive case filter

Is there's a way to change the filter from sensitive case to insensitive?

Thank you.

Upvotes: 0

Views: 2151

Answers (3)

Sivaraj-v
Sivaraj-v

Reputation: 390

  function filter(item) {
    // String Should Match Each Other
    /* for (var columnId in columnFilters) {
      if (columnId !== undefined && columnFilters[columnId] !== "") {
        var c = grid.getColumns()[grid.getColumnIndex(columnId)];
        if (item[c.field] != columnFilters[columnId]) {
          return false;
        }
      }
    } */

    for (var columnId in columnFilters) {
        if (columnId !== undefined && columnFilters[columnId] !== "") {
            var c = grid.getColumns()[grid.getColumnIndex(columnId)];
// This Case Sensitive
//if (!(item[c.field] && (""+item[c.field]).indexOf(columnFilters[columnId]) !== -1)) {
            if (!(item[c.field] && (""+item[c.field].toLowerCase()).indexOf(columnFilters[columnId].toLowerCase()) !== -1)) { 
// Case in-Sensitive
                return false;
            }
        }
    }
    return true;
  }

Upvotes: 0

Nate S
Nate S

Reputation: 43

Here’s the relevant section of a working example using the DataView filter. Notice the searchString variable is converted to lowercase when the value is first defined and then it's compared to lowercase strings within the myFilter function.

function myFilter(item, args) {
    if (args.searchString != "" && item["FirstName"].toLowerCase().indexOf(args.searchString) == -1 && item["LastName"].toLowerCase().indexOf(args.searchString) == -1) {
        return false;
    }
    return true;
}

....

$("#txtSearch").keyup(function (e) {
    Slick.GlobalEditorLock.cancelCurrentEdit();
    // clear on Esc
    if (e.which == 27) {
        this.value = "";
    }
    searchString = this.value.toLowerCase();
    updateFilter();
});

function updateFilter() {
    dataView.setFilterArgs({
        searchString: searchString
    });
    dataView.refresh();
}

// initialize the model after all the events have been hooked up
dataView.beginUpdate();
dataView.setItems(data);
dataView.setFilterArgs({
    searchString: searchString
});
dataView.setFilter(myFilter);
dataView.endUpdate();

Upvotes: 2

ganeshk
ganeshk

Reputation: 5621

Guessing you are talking about the DataView filter, the implementation of the filter functionality is totally up to you. Note the filter function used in the SlickGrid examples - that function is set as the filter using dataView.setFilter(your_function_here). So implement the filter function as you want and set it to the dataView

Upvotes: 1

Related Questions