columns.sortable.compare Function

A JavaScript function for comparing the values.

  • If the first argument is less than the second one, returns -1.
  • If both arguments are the same, returns 0.
  • If the first argument is greater than the second one, returns +1.

Example - defining the custom compare function

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


  $("#treeList").kendoTreeList({
    dataSource: {
      data: [
            { id: 1, parentId: null, item: "two" },
            { id: 2, parentId: 1, item: "one" },
            { id: 3, parentId: 1, item: "three" }
        ]
    },
    sortable: true,
    columns: [{
      field: "item",
      sortable: {
        compare: function(a, b) {
          return numbers[a.item] - numbers[b.item];
        }
      }
    }]
  });
</script>
In this article
Not finding the help you need? Improve this article