Question

I am using the below code to sort the value of the tree, it seems like the sorting happens based on CASE.

I am trying to figure out a way to perform case insensitive sorting, can someone please help me?

if(sortValue == 'Ascending') {
    $("#groupTree").data("kendoTreeView").dataSource.sort({ field: "text", dir: "asc" });
} else if(sortValue == 'Descending') {
    $("#groupTree").data("kendoTreeView").dataSource.sort({ field: "text", dir: "desc" });
}
Was it helpful?

Solution 2

Just thought of listing a sample code to help others who are in search of a work around to perform case-insensitive sorting when using Kendo datasource.

var homogeneous = new kendo.data.HierarchicalDataSource({
  data: [{
    "id":"1237",
    "text":"b",
    "encoded":false,
    "items":[{
      "id":"234",
      "text":"b1",
      "encoded":false,
      "items":[{
        "id":"456",
        "text":"se",
        "encoded":false,
        "items":[{
          "id":"567",
          "text":"BB",
          "encoded":false
        }]
      }]
    }]
  }, {
    id: 1,
    // lowercase foo should be after 'text:b' in case-insensitive sort
    text: "foo"
  }],
  schema: {
    parse: function(data) {
      for (var i = 0; i < data.length; i++) {
        data[i].lowerText = data[i].text.toLowerCase();
      }
      return data;
    },
    model: {
      id: "id",
      children: "items"
    }
  },
  sort: { field: "lowerText", dir: "asc" }
});

$("#tree").kendoTreeView({
  dataSource: homogeneous
});

OTHER TIPS

Even that your question says "sort in Kendo Tree View" it actually refers to Kendo DataSource.

Said so, it is not supported BUT in KendoUI forums there is solution that might work. Check it here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top