FlexGrid has a client ColumnLayout property that saves the column layout in the browser's localStorage. ColumnLayout gets or sets a JSON string containing a list of grid columns and their properties. It doesn't support the datamap column in the FlexGrid.
To see how it works, you can try doing the following:
FlexGrid supports server-side saving\loading of column layout. This is useful in situations where column layout needs to be saved in a database for presenting different views to different users.
The following image shows how a FlexGrid when ColumnLayout property is used to save the layout of FlexGrid. The example uses Sale.cs model as its datasource, added in the QuickStart section.
The following code examples demonstrate how to set Save and Load Column layout in a FlexGrid:
C# |
Copy Code
|
---|---|
public ActionResult Index() { var model = Sales.GetData(500); return View(model); } |
Razor |
Copy Code
|
---|---|
@using MVCFlexGrid.Models @using C1.Web.Mvc.Grid @model IEnumerable<Sale> <script> // Save or restore column layout in localStorage function saveColumnLayout() { var grid = wijmo.Control.getControl("#ovFlexGrid"); localStorage['columns'] = grid.columnLayout; } function loadColumnLayout() { var grid = wijmo.Control.getControl("#ovFlexGrid"), columnLayout = localStorage['columns']; if (columnLayout) { grid.columnLayout = columnLayout; } } </script> <input type="button" value="Save Column Layout" class="btn" onclick="saveColumnLayout()" /> <input type="button" value="Load Column Layout" class="btn" onclick="loadColumnLayout()" /> @(Html.C1().FlexGrid<Sale>() .Id("ovFlexGrid") .AutoGenerateColumns(true) .AllowSorting(true) .SelectionMode(SelectionMode.Cell) .Bind(bl => bl.InitialItemsCount(100).Bind(Model)) .CssClass("grid") .IsReadOnly(true) ) |