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
255
Get current settings of igGrid
posted

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

Parents
  • 5513
    Offline posted

    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



Reply Children