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 custom order Grid Grouping not by Alphabetically

Thread ID:

Created:

Updated:

Platform:

Replies:

142578 Feb 11,2019 05:52 AM UTC Feb 14,2019 06:54 AM UTC ASP.NET MVC - EJ 2 3
loading
Tags: Grid
afiqdoherty
Asked On February 11, 2019 05:52 AM UTC

Hi,

I've got a new request from client regarding the Grouping functions. By default, the grid will list all data based on channel starting from RED, YELLOW and GREEN. On first load, I already sort the list earlier in my stored procedure using Order By for the Channel Color. 

Currently, it is group by in Alphabetically Order (A-Z) when I drag the Channel Column to group. But, for Grouping function, my client also need the list to be grouped by Channel Order too. Hope you can help me on this

*please note that grid is not group by default.

Thanks :D



Pavithra Subramaniyam [Syncfusion]
Replied On February 14, 2019 06:32 AM UTC

Hi Muhammad, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed your requirement. We would like to inform you that by default when you group a column in Grid, the column’s data will be sorted and then Grid will show the Grouped columns. We could see that your requirement is that you would like to display the Grid after Grouping as like sorting is not applied in Grid. We have prepared a sample based on this requirement. We are attaching the sample for your convenience. Please download the sample from the link below, 
 
In the above sample, we have set the initial sorted columns in Grid(initial sort to “CustomerID” column) and use the “SortComparer” function for “CusomerID”. In the sortComparer function we will be returning -1(which restrics sort). Now if you group the column in which the sort comparer is applied(say CustomerID column), it won’t show the Group in alphabetical order. Please refer the code example below, 
 
 
@{ 
    List<object> cols = new List<object>(); 
    cols.Add(new { field = "CustomerID", direction = "Ascending" });     //Column to apply initial sort 
} 
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).Columns(col => 
{ 
    col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
    col.Field("CustomerID").HeaderText("Customer Name").SortComparer("sortComparer").Width("150").Add(); 
    ... 
}).AllowPaging().AllowSorting(true).SortSettings(sort => sort.Columns(cols)).AllowGrouping(true).Render() 
 
<script> 
    function sortComparer(reference, comparer) {     //Here you can define your custom sort function 
       return -1;     //return -1 will restrict the sort 
    }; 
</script> 
 
 
 
Please refer the screenshot below, 
 
 
 
Documentation :  
 
Please get back to us if you need further assistance. 
 
Regards,  
Pavithra S. 


afiqdoherty
Replied On February 14, 2019 06:52 AM UTC

Wow...thanks sooo muchh Pavithra:))) it works :D

my result :)



regards,

afiq

Pavithra Subramaniyam [Syncfusion]
Replied On February 14, 2019 06:54 AM UTC

Hi Muhammad,  

Thanks for your update. 

We are happy to hear that the provided information helps you. 

Please contact us if you need any further assistance. As always, we will be happy to assist you.  

Regards,  
Pavithra S. 


CONFIRMATION

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

This page will automatically be redirected to the 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

;