Default Sort for Kendo Grid (MVC)

1 Answer 8448 Views
Grid
Ken Lewis
Top achievements
Rank 1
Ken Lewis asked on 01 Mar 2013, 04:58 PM
I want the following grid to start off sorted by Name. How do you do that using the HTML helper?

@(Html.Kendo().Grid(Model)   
    .Name("MyGrid")
    .Columns(columns =>
    {
        columns.Bound(m => m.Name);
        columns.Bound(m => m.Title);
        columns.Bound(m => m.Email);
    })
    .Pageable()
    .Sortable()
)
Thanks,

Ken
Nikolay Rusev
Telerik team
commented on 04 Mar 2013, 09:43 AM

Hello Ken,

You can configure the DataSource to apply initially sort expressions. For example: 
 

.DataSource(dataSource => dataSource
        .Ajax()
        .Sort(sort => sort.Add("City").Ascending()) // <-- initial sort expression
        .Read(read => read.Action("Index", "Home"))
    )


Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
AndyRutter
Top achievements
Rank 2
commented on 16 Oct 2014, 08:18 AM

No and they still still give many examples for MVC controls. Took me an age to find something I found immediately for the no MVC UI.
Why is this small example not on the sorting page of the MVC documentation..?
So frustrating....!!!
Nikolay Rusev
Telerik team
commented on 20 Oct 2014, 06:11 AM

Hello Brian,

These settings are usually listed in the API reference section of the documentation as linked in the previous post.

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 

1 Answer, 1 is accepted

Sort by
0
Ken Lewis
Top achievements
Rank 1
answered on 04 Mar 2013, 03:35 PM
Nikolay,

I'm using server binding so I added the following to my Grid configuration and it works great. The demos don't seem to give a lot of Server binding examples, so I didn't know I could use the same data source settings.

.DataSource(dataSource => dataSource
    .Server()
    .Sort(sort => sort.Add("Name").Ascending())   
)

Thanks for pointing me in the right direction.

Ken
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
commented on 15 Oct 2024, 09:03 AM

There is no .Server() anymore :-(
Alexander
Telerik team
commented on 16 Oct 2024, 10:18 AM

Hi Stefan,

If you wish to configure the Grid for Server Binding, I suggest following a similar implementation as the following demo, should you happen to have stumbled upon any pitfalls:

In addition, the .Server() API configuration has not been obsoleted.

Tags
Grid
Asked by
Ken Lewis
Top achievements
Rank 1
Answers by
Ken Lewis
Top achievements
Rank 1
Share this question
or