Custom client side sorting with grouping

Hi


Is it possible to perform custom sorting on a grid when it has been grouped? So we would want the grouped column to be sorted on.


3 Replies

PS Pavithra Subramaniyam Syncfusion Team April 29, 2022 12:59 PM UTC

Hi Malcolm,


Thanks for contacting Syncfusion support.


You can customize the default sorting behavior of a column by using “Sort Comparer” feature of the Grid column. Please refer to the below code example and API link for more information.


<div class="control-section">

    @Html.EJS().Grid("BatchEditing").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>

{

   col.Field("CustomerID").HeaderText("Customer ID").SortComparer("customerIDSort").Width("150")..Add();

 

}).AllowSorting().AllowGrouping().AllowPaging().PageSettings(page => page.PageCount(2)) Render()

</div>

<script>

    function customerIDSort(reference, comparer) {

        // you can return 1, 0 or -1 based on your sort preference

        if (reference < comparer) {

            return 1;

        }

 

        if (reference > comparer) {

            return -1;

        }

        return 0;

    }

 

</script>


API: https://ej2.syncfusion.com/javascript/documentation/api/grid/columnModel/#sortcomparer


Please get back to us if you need further assistance on this.


Regards,

Pavithra S



MV Malcolm van Staden April 29, 2022 02:08 PM UTC

Hi


Thank you for reply - the provided solution is applicable to the EJ2 suite? Is this forum not for the EJ1 controls? 



PS Pavithra Subramaniyam Syncfusion Team May 2, 2022 02:22 PM UTC

Hi Malcolm,


Currently, we don’t have support for sortComparer in EJ1. And currently, EJ1 controls are not in active development. So, we have no plans to develop any features in the essential java script1 controls in the future.


Kindly get back to us for further assistance.


Regards,

Pavithra S


Loader.
Up arrow icon