Edit this page

columns.sortable.compare Function

A JavaScript function which is used to compare the values - should return -1 if first argument is less than second one, 0 if both are the same or +1 if the first one is greater than second one.

Example - define 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>
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy