0

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" });
}
OnaBai
  • 40,767
  • 6
  • 96
  • 125
Learner
  • 2,303
  • 9
  • 46
  • 81

2 Answers2

1

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

OnaBai
  • 40,767
  • 6
  • 96
  • 125
0

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
});
Learner
  • 2,303
  • 9
  • 46
  • 81