We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to do default sorting in MVC Grid

Thread ID:





119706 Jul 23,2015 11:56 AM UTC Jul 28,2015 11:52 AM UTC ASP.NET MVC 3
Tags: Grid
Rene Koch
Asked On July 23, 2015 11:56 AM UTC

Hey guys,

we are using your MVC grid and after a lot of complications and try-and-error-handling (because in my opinion there is way to less API / Description from your side) I have handled the most problems.
Neither then less - your control looks beautiful and is very fast and responsive.

What I really miss here in ym MVC Grid is the option to have a default sorting - how to do that?

At the moment this is my sorting algorythm of my controller:
            if (String.IsNullOrEmpty(orderby))
                allDataForList = allDataForList.OrderByDescending(x => x.EndDate);
                bool desc = false;
                if (orderby.IndexOf("desc") > 0)
                    desc = true;
                    orderby = orderby.Remove(orderby.IndexOf(" desc"));
                allDataForList = LinqExtensions.OrderByField(allDataForList, orderby, desc);
which means: If there is no sorting, sort on EndDate. But the problem here is, that there is no icon displayed on the front end for the sorting then and if I click on EndDate Coloum there will be the exact sorting I have done allready. Feels buggy.

I allready tried to do this by javascript with something like:
     $("#Grid").ejGrid("sortColumn", "ProjectID", "Descending");
But this seems complete buggy as hell - the sort works, but the sorting-icon will be displayed wrong (at first it will be displayed correct but on a click on this coloum there is a second sorting-icon which seems to be a obvious bug).

Do you have a solution for this?

Alan Sangeeth S [Syncfusion]
Replied On July 27, 2015 01:09 PM UTC

Hi Rene,

Query 1: “Sorted Column at initial Grid render”

We are glad to let you know that we have achieved your requirement using “SortSettings” Grid property. Please refer the following code snippets.


SortSettings(sort=>sort.SortedColumns(col=> col.Field("CustomerID").Direction(SortOrder.Descending).Add()))


For your convenience we have created a sample and the same can be downloaded from below location.

Sample: http://www.syncfusion.com/downloads/support/forum/119706/ze/EJGrid-859647982

Query 2: “two sort icons issue with sortColumn Grid method”

We have analyzed your code snippets and found that you have used “Descending” string with first character “D” capitalized which is the cause of the issue.

We suggest you to pass the direction value in small case as “descending” to resolve the issue. Please refer the following code snippets.

$("#Grid").ejGrid("sortColumn", "ProjectID", "descending");

Please refer the following API document for further reference.

Please let us know if you need any further assistance.

Alan Sangeeth S

Rene Koch
Replied On July 27, 2015 01:10 PM UTC

Thank you very much

Madhu Sudhanan P [Syncfusion]
Replied On July 28, 2015 11:52 AM UTC

Hi Rene,

Thanks for the update. Please get back to us if you require further assistance. We will be happy to help you out.

Madhu Sudhanan. P


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon