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
605
Saving and restoring igGrid filters, sorting, and columns
posted

Hi,

I'd developing an ASP.NET MVC application using Infragistics Grid. I'd like to let users save the filtering, sorting, and column hiding options they set on the grid, using a Save button on the UI. So, the setting are not to be saved automatically, but only when the button is pressed. This will extract the setting from the grid, and post them to the server, to store in DB. This part works nicely:

var gridSortingSettings = $("#CompaniesGrid").igGridSorting("option", "columnSettings");
var gridColumnSettings = $("#CompaniesGrid").igGrid("option", "columns");
var gridFilteringSettings = $("#CompaniesGrid").igGridFiltering("option", "columnSettings");

var url = '@Url.Action("SaveGridSettings")';
$.ajax({
type: "POST",
url: url,
data: JSON.stringify({
sortingSettings: gridSortingSettings,
columnSettings: gridColumnSettings,
filteringSettings: gridFilteringSettings
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
});

What i'd like to do now, is to be able to restore these setting from the database, when loading the grid. I can retrieve these setting as JSON, however, I found no example of setting these options using the MVC View of the grid, as the grid is initialized this way. I have no idea how to set a JSON here. Do you have any suggestion, maybe better ideas for restoring these settings?

I tried setting it manually, this way, using a Restore button (would't be working this way, just for testing):
var gridSortingSettings = <get JSON from server...>
 $('#CompaniesGrid').igGridSorting("option", "columnSettings", gridSortingSettings);

Then, reading it again: 
var gridSortingSettingsReadBack = $("#CompaniesGrid").igGridSorting("option", "columnSettings");

I found that however the JSON i read back changes as expected, the grid shows no difference. Maybe I need some way to refresh? Anyway, the perfect solutuon would be to make this load automatically from the MVC View when the grid is initializing grid, like setting @Html.Infragistics().Features().Sorting().Whatever()... in the View.

regards,

Peter

Parents
  • 25665
    Offline posted

    Hello Peter,

    Thank you for contacting Infragistics!

    Since you are using the MVC wrappers of the Ignite UI controls you can execute C# code inside the wrappers. So instead of trying to apply the settings after the grid is setup and then refresh you can apply them when initializing the grid. For example:

    features.Updating().EditMode(GridEditMode.Cell).ColumnSettings(settings =>
                    {
                        if (editor == true)
                        {
                            settings.ColumnSetting().ColumnKey("ProductID").EditorType(ColumnEditorType.Combo).ComboEditorOptions(options =>
                            {
                                options.DataSourceUrl(Url.Action("GetComboData", "Home")).ShowDropDownButton(true).TextKey("ProductID").ValueKey("ProductID");
                            });
                        }
                       
                    });

    So you can loop/parse you saved settings and apply them in initialization.

    Please let me know if you have any further questions concerning this matter.

Reply Children