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);
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); } });
$("#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"); });
features: [
{
name: "Sorting",
mode: "multi",
persist: false
.
]
......
$("#grid").igGrid("dataBind");
I hope you find my information helpful.
Please let me know if you need any further assistance with this matter.
I am glad that you find my suggestion helpful.
Hi,
Below two methods are not working
$(".selector").igGridSorting("clearSorting");
$(".selector").igGridSorting("unsortColumn","key");
Thanks,
Ponprabhu