Hi,
is it possible to get the current Settings of an igGrid table?
Background: I want to store them in a Cookie to Show the table exactly with the same Settings (sorting, column ordering, grouping) as the user has set when he used the table the last time.
Thanks.
Michael
Hello Michael,
There is no unified way for restoring the grid state but you could certainly implement a solution on your own using grid's API. For example, using the features you mentioned, you can get the currently sorted columns with:
$("#grid1").igGridSorting("option", "columnSettings");
Traversing the array returned you'll notice that sorted columns have the currentSortDirection property set. The columnSettings option works both ways. Setting the same property for columns on grid's initialization will pre-sort it as required. You can read more about this option here: http://help.infragistics.com/jQuery/2013.2/ui.iggridsorting#options. The downside of this method is that the sort style is not reapplied. Please, let me know if you need to restore the sort style as well because it'll require a different approach.
For GroupBy it's best to use the groupedColumns option to get the currently grouped columns and restore them by setting the isGroupBy property in the columnSettings collection. Again you can learn more about these options here: http://help.infragistics.com/jQuery/2013.2/ui.iggridgroupby#options
$("#grid1").igGridGroupBy("option", "groupedColumns");
An example of how the grid definition will look with some columns pre-sorted and pre-grouped:
$("#grid1").igGrid({
...
features: [ { name: "Sorting", columnSettings: [ { columnKey: "UnitPrice", currentSortDirection: "asc" } ] }, { name: "GroupBy", columnSettings: [ { columnKey: "ProductDescription", isGroupBy: true } ] }]
});
The column order is probably the easiest as you can basically serialize what you receive from:
$("#grid1").igGrid("option", "columns");
and then deserialize it to initialize the grid with the result directly.
I hope this helps! Please let me know if you have any other questions and/or concerns!
Best regards,
Stamen Stoychev
Thank you for posting in our forum.
In addition to the response of my colleague Stamen I have attached a sample presenting how to save igGrid column states. In this sample it is shown how to keep the hidden column property.
The behavior is achieved by using the javascript deep copy object. Having the states saved in a javascript object you could also send them to the server and save them if needed.
If you have any further questions or comments don’t hesitate to contact us again.