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
20
How to Clear Sorting For Columns In Grid
posted

I need to clear sorting for the columns in the grid. I tried setting the currentSortDirection to "null" but it doesn't work. I also tried igGridSorting("destroy") which almost works, but then I am unable to sort again without recreating grid.

var colSettings = $grid.igGridSorting("option", "columnSettings"); for (i = 0; i < colSettings.length; i++) { if (typeof colSettings[i].currentSortDirection != "undefined") { colSettings[i].currentSortDirection = null; } } $grid.igGridSorting("option", "columnSettings", colSettings);

Parents
  • 17590
    Verified Answer
    Offline posted

    Hello A J Woods,

    Thank you for posting in our community.

    I can suggest two approaches for achieving your requirement.

    First is to loop all the columns and apply unsortColumn method of igGrid Sorting feature. For example:

    $("#unsortBtn").on("click", function () {

       var colLength = $("#grid").igGrid("option", "columns").length;

       var colKey;

       for (var i = 0; i < colLength; i++) {

        colKey = $("#grid").igGrid("option", "columns")[i].key;

        $("#grid").igGridSorting("unsortColumn", colKey);

    }

    });

    Another option is to turn off the persist feature of the sorting behavior and just rebind the grid. This option enables/disables sorting persistence between states. By default this feature is enabled.

    For example:

    features: [

    {

    name: "Sorting",

    mode: "multi",

    persist: false

    }

    .

    .

    ]

    ......

    $("#unsortBtn").on("click", function () {

    $("#grid").igGrid("dataBind");

    });

    I hope you find my information helpful.

    Please let me know if you need any further assistance with this matter.

Reply Children