0

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

Thank you.

neoswf
  • 4,730
  • 6
  • 39
  • 59
  • 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. – ganeshk May 29 '12 at 20:27
  • Thank you again man! your'e the best! :) Hey- here's a tip from me to you - transform your comment into an answer, than you'll get points when I'll approve your answer as the correct one. Than delete this comment :))) – neoswf May 29 '12 at 20:51
  • & regarding my question- how can I unsensitive it? I will lowercase the dataView string, and than there won't be any issue? #thinking.... – neoswf May 29 '12 at 20:54
  • Yeah - use one case (either lower or upper) of both left-hand and right-hand side of compare and that should do it. You could use Javascript prototypes to register a function/operator for this if you will use this often in your JS code – ganeshk May 29 '12 at 20:58

3 Answers3

2

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();
Nate Strech
  • 43
  • 1
  • 6
1

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

ganeshk
  • 5,583
  • 3
  • 27
  • 31
  • 1
    I have commited into SG repository at Git this modification. I think it needs to be the default behaviour, Doesn't make sense that the user will want to search using a case-sensitive filter. https://github.com/mleibman/SlickGrid/pull/362 – neoswf May 30 '12 at 18:47
0
  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;
  }
Sivaraj-v
  • 371
  • 1
  • 3
  • 17