Edit this page

columns.sortable Boolean |Object (default: true)

If set to true the user can click the column header and sort the grid by the column field when sorting is enabled. If set to false sorting will be disabled for this column. By default all columns are sortable if sorting is enabled via the sortable option.

Example - disable sorting

<div id="grid"></div>
<script>
$("#grid").kendoGrid({
  columns: [
    { sortable: false, field: "id" },
    { field: "name" }
  ],
  sortable: true,
  dataSource: [ { id: 1, name: "Jane Doe" }, { id: 2, name: "John Doe" } ]
});
</script>

columns.sortable.compare Function

A JavaScript function which is used to compare the values. It has the same signature as the compare function accepted by Array.sort.

The basic function implementation is as follows (pseudo-code):

    function compare(a, b, descending) {
      if (a is less than b by some ordering criterion) {
        return -1;
      }


      if (a is greater than b by the ordering criterion) {
        return 1;
      }

      // a must be equal to b
      return 0;
    }

One notable exception is that we also supply a third parameter that indicates the sort direction (true for descending). See How-to: Stable Sort in Chrome for more details on how this can be useful.

Example - define custom compare function

<div id="grid"></div>
<script>
    var numbers = {
        "one"  : 1,
        "two"  : 2,
        "three": 3
    };

    var dataSource = new kendo.data.DataSource({
        data: [
            { id: 1, item: "two" },
            { id: 2, item: "one" },
            { id: 3, item: "three" }
        ]
    });

    $("#grid").kendoGrid({
        dataSource: dataSource,
        sortable: true,
        columns: [{
            field: "item",
            sortable: {
                compare: function(a, b) {
                    return numbers[a.item] - numbers[b.item];
                }
            }
        }]
    });

</script>

columns.sortable.initialDirection String (default: asc)

Determines the inital (from un-sorted to sorted state) sort direction. The supported values are asc and desc.

Example - disable sorting

<div id="grid"></div>
<script>
$("#grid").kendoGrid({
  columns: [
    {
      field: "id",
      sortable: {
        initialDirection: "desc"
      }
    },
    { field: "name" }
  ],
  sortable: true,
  dataSource: [ { id: 1, name: "Jane Doe" }, { id: 2, name: "John Doe" } ]
});
</script>
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy