Search code examples
parsingfiltergridkendo-gridkendo-template

Kendo Filter on parsed input value


My example: http://dojo.telerik.com/oWABE/2

Here I have a data object containing "status" which is an integer! (it is 1,2 or 3)

In my Grid that masks to New, Pending and Closed

To show the strings (New, Pending and Closed) I have created a parse function in the shema -> for filtering to work on the parsed values one cannot use a template in the columns definition, but has to parse it in the datasource!

Status: { type: "int",
         parse: function(status) {    
         console.log(status,"stat");            
           switch(status){
             case 1: return"New"; break;
             case 2: return"Pending"; break;
             case 3: return"Solved"; break;
             case 5: return"Closed"; break;
          }
     }
},

There is a "console.log" when this parser gets called and what I notice is that AFTER! I filter for "New" the log reads:

n stat
undefined "stat"

...when I first run the page the log reads (as expected):

1 "stat"
2 "stat"
3 "stat"

The Filter does not work (try filtering for "New" as an example)

Any help?


Solution

  • The "schema.parse option" needs to be used!

    dataSource: {
                  data: data,
                  schema: {
                    parse: function(response) {
                      var products = [];
                      for (var i = 0; i < response.length; i++) {
                        switch(response[i].Status){
                          case 1: response[i].Status = "New"; break;
                          case 2: response[i].Status = "Pending"; break;
                          case 3: response[i].Status = "Solved"; break;
                          case 5: response[i].Status = "Closed"; break;
                        }   
                        console.log(response[i]);
                        products.push(response[i]);
                      }                         
                      return products;
                    },
                    model: {
                      fields: {                         
                        OrderID: { type: "number" },           
                        Status: { type: "string"},
                        ShipCountry: { type: "string" }
                      }
                    }
                  }
                },
    

    Here is the answer from Kendo: http://www.telerik.com/forums/kendo-filter-on-parsed-input-value