Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort numeric with string values in Kendo-Grid

I am using Kendo-Grid which is having a column has values of both number & string (NA). Any idea how to sort them?

like image 347
JPN Avatar asked Sep 25 '13 19:09

JPN


1 Answers

You can sort them using a custom compare function. Here is some sample code which will put items with 'N/A' on top:

$("#grid").kendoGrid({
  dataSource: [
    { price: 1 },
    { price: "N/A" },
    { price: 20 },
    { price: 2 }
  ],
  sortable: true,
  columns: [
    {
      field: "price",
      sortable: {
        compare: function(a, b) {
          var x = a.price;
          var y = b.price;

          if (x == 'N/A') {
            x = 0;
          }

          if (y == 'N/A') {
            y = 0;
          }

          return x - y;
        }
      }
    }
  ]
});

Here is a live demo: http://jsbin.com/urUXOCa/1/edit

like image 116
Atanas Korchev Avatar answered Sep 17 '22 20:09

Atanas Korchev