This is a migrated thread and some comments may be shown as answers.

[Solved] Get Sorted Column name and order in Controller

3 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ashok
Top achievements
Rank 1
Ashok asked on 16 Jun 2011, 02:34 AM

Here is our requirement:
When home page is loaded, page is loaded with data in grid. User can perform sort on grid data. I want to get this column name in controller for some processing.

We are using single column sort.

How do I get sorted column name and sort order in MVC controller?


3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 16 Jun 2011, 08:10 AM
Hello Tejas,

In order to get the sort expression from the controller you should use GridCommand. I have attached a small sample which demonstrates how to achieve this both in case of server or ajax binding

All the best,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ashok
Top achievements
Rank 1
answered on 16 Jun 2011, 10:16 PM
Hello Rosen,

Thank you for sample. It helped a lot. One last thing before I close this ticket..

I am storing Sort info and when user comes back to Grid again, I apply sort on data in MVC controller. Everything works like charm.

However Sort Direction Indicator is not showing up. How do I show Sort Direction Indicator based on column?

0
Rosen
Telerik team
answered on 17 Jun 2011, 08:06 AM
Hi Tejas,

Unfortunately, I'm not sure how your are setting the sort expression in your code. However, you may set initial sort expression and order using the Sortable option similar to the following:

.Sortable(sorting => sorting.OrderBy(order =>
{
    if ((bool)ViewData["contactName"])
    {
        order.Add(o => o.Customer.ContactName).Descending();
    }
}))

Regards,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Ashok
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Ashok
Top achievements
Rank 1
Share this question
or