Ben Cameron
Ben Cameron

Reputation: 4413

Kendo UI Grid, sorting datasource groups

I have a page that has a Kendo grid on it. It is calling an ajaz web request to get its data. Once the data has been returned it is grouped in the frontend. The problem I am having is sorting the groups. What is the best way to do this?

My MVC view code looks something like this...

    .DataSource(dataSource => dataSource
        .Ajax()
        .Group(groups =>
        {
            groups.Add(c => c.groupingField);
        })
        .Read(...))

I have tried to use the sort method but am not sure where to put it when the data is coming from an ajax call.

Upvotes: 1

Views: 1407

Answers (2)

Ben Cameron
Ben Cameron

Reputation: 4413

I found that adding the below line to the datasource call solved my problem...

  .Sort(sort => sort.Add("FIELD_NAME").Ascending()) 

Upvotes: 1

Jarosław Kończak
Jarosław Kończak

Reputation: 3407

You need to provide groups in correct order in .Group() method. I don't have mvc version installed but for example it should be ok:

 var groupList = new List<string> { "Gr1", "Gr2" };

.DataSource(dataSource => dataSource
    .Ajax()
    .Group(groups =>
    {
        groupList.Select(x => groups.Add(x));
    })
    .Read(...))

Upvotes: 0

Related Questions