Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
360
Sorting column from left to right instead of click history order.
posted

Hello,

We are currently migrating our product from an old grid component to the last igGrid component bind to an ODataSource. I would  like to know if  it's possible to achieve the same sorting  feature that we had before: 

for exmple I have a grid  with   5 columns like below:  

 | Id | FirstName | LastName | Age | Town |

If I click on LastName then  FirstName the sort order with the igGrid is the click order:

LastName, FirstName.

I would like to keep the sort order of my old grid that was from the column position (left to right):

FirstName,LastName.

Is there a way to do so ?

Thanks.

Btw: I forgot I am using grouping too that should be first in the $orderby of the OData request.

Parents
No Data
Reply
  • 17590
    Verified Answer
    Offline posted

    Hello Vincent,

    What I can suggest in order achieve the required behavior is to handle columnSorting event, check whether a particular condition is met (for example is both First Name and Last Name columns exist in filtering expressions collection) and then modify the sorting expressions of the data source so that "First Name" expression is before "last Name" expression. Afterwards, using the sortMultiple method you can apply the new expressions and cancel the default sorting.

                        {
                            name: "Sorting",
                            mode: "multi",
                              columnSorting: function (evt, ui) {
                                if (ui.newExpressions.filter(e => e.fieldName === 'FirstName').length > 0 &&
                                    ui.newExpressions.filter(e => e.fieldName === 'LastName').length) {
                                    const newExpressions = [
                                        { fieldName: "FirstName", isSorting: true, dir: "asc", compareFunc: null, layout: null },
                                        { fieldName: "LastName", isSorting: true, dir: "asc", compareFunc: null, layout: null }
                                    ];
                                    ui.owner.grid.dataSource.settings.sorting.expressions = newExpressions;
                                    ui.owner.sortMultiple();
                                    return false;
                        }
                           


    Attached you will find a small sample illustrating my suggestion for your reference.
    Please keep in mind that this behavior is not provided put of the box and the approach can be considered as a workaround on an application level.

    Please let me knw if you need any further assistance.

    8371.igGridSortMultipleColumnInOrder.zip

Children