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. Image for the cookie policy date
close icon

How to group a column and put in descending order as default?

Hello,

I'm using the grid and doing the initial grouping of the "Date" column, but I would like the default to be descending. How to adjust it?

Thanks


    <ejs-grid id="GridProducaoEstoque"

                  allowTextWrap="true"

                  locale="pt"

                  height="100%"

                  allowSorting="true"

                  allowFiltering=true

                  allowExcelExport="true"

                  enablePersistence="true"

                  allowGrouping="true"

                  recordDoubleClick="doubleClickGridProducaoEstoque"

                  allowPaging="true"

                  toolbarClick="toolbarClick"

                  toolbar=toolbarItemsEstoqueGrid>

            <e-data-manager url="/EstoqueMovimenta/UrlDataSource"

                            removeUrl="/EstoqueMovimenta/DeleteEstoqueMovimenta"

                            adaptor="UrlAdaptor">

            </e-data-manager>

            <e-grid-groupsettings columns="@(new string[] {"datamovimenta"})" allowReordering="true"></e-grid-groupsettings>






3 Replies

RS Rajapandiyan Settu Syncfusion Team November 22, 2022 09:48 AM UTC

Hi Roberto,


Thanks for contacting Syncfusion support.


To group the columns in descending order at initial render, we suggest you to sort that columns in descending order in the initial settings of Grid to achieve your requirement.


Initial Sort: https://ej2.syncfusion.com/documentation/grid/sorting/#initial-sort


 

[index.cshtml]

@{

    List<object> cols = new List<object>();

    cols.Add(new { field = "TrackedDate", direction = "Descending" });

}

 

<ejs-grid height="273" id="GridProducaoEstoque" created="created">

    <e-grid-sortsettings columns="cols"></e-grid-sortsettings>

    <e-grid-groupsettings columns="@(new string[] {"TrackedDate"})" allowReordering="true"></e-grid-groupsettings>

</ejs-grid>

 


If you want to Group the columns in descending order after the initial rendering, you can achieve this by overriding the following method in the created event of Grid.


Created: https://ej2.syncfusion.com/javascript/documentation/api/grid/#created


 

    function created(args) {

        this.groupModule.groupAddSortingQuery = function (colName) {

            let i = 0;

            while (i < this.parent.sortSettings.columns.length) {

                if (this.parent.sortSettings.columns[i].field === colName) {

                    break;

                    }

                    i++;

            }

            if (this.parent.sortSettings.columns.length === i) {

                this.parent.sortSettings.columns.push({

                    field: colName,

                    direction: 'Descending',

                    isFromGroup: true,

                });

            } else if (!this.parent.allowSorting) {

                this.parent.sortSettings.columns[i].direction = 'Descending';

            }

        }

    }

 


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/core_grid_url_group_descending1607892936.zip


Regards,

Rajapandiyan S



RO Roberto November 23, 2022 10:33 AM UTC

Hi,


It´s working.


Thanks.



RS Rajapandiyan Settu Syncfusion Team November 24, 2022 03:17 AM UTC

Hi Roberto,


We are happy to hear that you have achieved your requirement with the solution provided.


Please get back to us if you need further assistance.


Regards,

Rajapandiyan S


Loader.
Live Chat Icon For mobile
Up arrow icon