This is a migrated thread and some comments may be shown as answers.

Kendo Grid Filtering Case Insensitivity

2 Answers 846 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 17 Jan 2014, 03:50 PM
Hi Kendo,

I'm trying to make filtering for one 'term' case insensitive.   The code below works if the 'tolower' is removed.  What I'm trying to do is pass on through the odata to the database the idea that it needs to take the database column and apply a 'lower case' to it and then do the substring operation, making the filter case insensitive.  Is there any way to get the 'tolower' on the field to work with filtering?  Thanks for your help.

Bill

parameterMap: function (data, type) {
     if (type == "read") {
          var grid = $("#grid").data("kendoGrid");
          var currentFilter = grid.dataSource.filter();
          if (currentFilter) {
                if (currentFilter.filters[1] === undefined & currentFilter.filters[0].field !== "Field1" &             currentFilter.filters[0].field !== "Field2" & currentFilter.filters[0].field !== "Field3") {
                    data.filter.logic = "or";
                    var stringValue = "";
                    stringValue = currentFilter.filters[0].value.toString();
                    var new_filter = { field: tolower(currentFilter.filters[0].field), operator: currentFilter.filters                [0].operator, value: stringValue.toLowerCase() };
                    data.filter.filters.push(new_filter);
                    new_filter = { field: currentFilter.filters[0].field, operator: currentFilter.filters[0].operator, value:          stringValue.toUpperCase() };
                    data.filter.filters.push(new_filter);
}
}

var newMap = kendo.data.transports.odata.parameterMap(data);
delete newMap.$format; // not currently supported by webapi.
return newMap;
}
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Bill
Top achievements
Rank 1
answered on 17 Jan 2014, 04:23 PM
Modified the following line and it fixed the problem and it now works...

var new_filter = { field: "tolower(" + currentFilter.filters[0].field + ")", operator: currentFilter.filters[0].operator, value: stringValue.toLowerCase() };
0
Bill
Top achievements
Rank 1
answered on 17 Jan 2014, 05:59 PM
Here's a more complete solution for the Kendo grid filtering case insensitivity using odata.  Hope it helps somebody else out there working on the same issue...  Using the parameterMap and then looping through the filter collection is the trick.  And filtering collection may have sub collections of filters.  Adding the 'tolower' to the field and then lower casing the filter value does the trick...

$("#grid").kendoGrid({
    dataSource: {
    type: "odata",
    transport: {
     read: {
           url: url,
           dataType: "json",
           headers: { "Accept": "Application/json; odata=verbose" }
     }
     ,
    parameterMap: function (data, type) {
         if (type == "read") {
             var grid = $("#grid").data("kendoGrid");
             var currentFilter = grid.dataSource.filter();
             if (currentFilter) {
                for (var index in data.filter.filters) {
                    if (data.filter.filters[index].field !== "PersonName" & data.filter.filters[index].field !== "PersonJob" &                          data.filter.filters[index].field !== "PersonFun") {
                       if (data.filter.filters[index].field !== undefined) {
                             data.filter.filters[index] = {
                                  field: "tolower(" + data.filter.filters[index].field + ")",
                                  operator: data.filter.filters[index].operator,
                                  value: data.filter.filters[index].value.toLowerCase()
                            }
                       }
                      else {
                           for (var index2 in data.filter.filters[index].filters) {
                               if (data.filter.filters[index].filters[index2].field !== "PersonName" & data.filter.filters         [index].filters[index2].field !== "PersonJob" & data.filter.filters[index].filters[index2].field !== "PersonFun") {
                                    if (data.filter.filters[index].filters[index2].field !== undefined) {
                                         data.filter.filters[index].filters[index2] = {
                                                field: "tolower(" + data.filter.filters[index].filters[index2].field + ")",
                                                operator: data.filter.filters[index].filters[index2].operator,
                                                value: data.filter.filters[index].filters[index2].value.toLowerCase()
                                               }
                                   }
                           }
                     }
              }
         }
      

}

        var newMap = kendo.data.transports.odata.parameterMap(data);
        delete newMap.$format; // not currently supported by webapi.
        return newMap;
}
}
},

pageSize: 100,
serverPaging: true,
serverFiltering: true,
serverSorting: true
Tags
Grid
Asked by
Bill
Top achievements
Rank 1
Answers by
Bill
Top achievements
Rank 1
Share this question
or