Learner
Learner

Reputation: 2339

How to perform case-insensitive sort in Kendo Tree view?

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" });
}

Upvotes: 0

Views: 1782

Answers (2)

Learner
Learner

Reputation: 2339

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
});

Upvotes: 0

OnaBai
OnaBai

Reputation: 40887

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

Upvotes: 1

Related Questions