Persisting Layout
By default, FlexGrid allows users to resize and reorder columns.
It is easy to extend this and allow users to select columns as well. For example, you can use the MultiSelect control below to select the columns to be displayed on the grid:
Id
Country
Product
Active
Downloads
Sales
Expenses
Overdue
0
US
Phones
145,248
81,732.54
38,401.13
1
Germany
Computers
111,632
20,603.32
27,944.24
2
UK
Cameras
181,205
44,217.79
48,877.49
3
Japan
Stereos
54,740
29,190.63
23,365.74
4
Italy
Phones
126,531
46,951.19
49,107.56
5
Greece
Computers
6,073
86,237.02
49,767.35
Id
Country
Product
Active
Downloads
Sales
Expenses
Overdue
0
You can use the grid's columnLayout property to allow users to save and restore column layouts. Click the buttons below to see how this works.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | // This file locates: "Scripts/Lesson/C1FlexGrid/ColumnsColumnLayout.js". c1.documentReady(function () { var theGrid = wijmo.Control.getControl( '#theGrid' ); // populate column picker var cols = []; theGrid.columns.forEach(function (col) { cols.push({ header: col.header, binding: col.binding, visible: true }); }); var columnPicker = wijmo.Control.getControl( '#columnPicker' ); columnPicker.itemsSource = cols; columnPicker.checkedItemsChanged.addHandler(function (s, e) { cols.forEach(function (item) { theGrid.getColumn(item.binding).visible = item.visible; }) }); // save/restore layout buttons document.getElementById( 'btnSave' ).addEventListener( 'click' , function() { localStorage.setItem( 'myLayout' , theGrid.columnLayout); }); document.getElementById( 'btnRestore' ).addEventListener( 'click' , function() { var layout = localStorage.getItem( 'myLayout' ); if (layout) { theGrid.columnLayout = layout; } }); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Web.Mvc; namespace LearnMvcClient.Controllers { public partial class C1FlexGridController : Controller { // GET: ColumnsColumnLayout public ActionResult ColumnsColumnLayout() { return View(Models.FlexGridData.GetSales()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | @model IEnumerable< FlexGridData.Sale > < h1 > @Html .Raw(Resources.C1FlexGrid.ColumnsColumnLayout_Title) </ h1 > < p > @Html .Raw(Resources.C1FlexGrid.ColumnsColumnLayout_Text1) </ p > < p > @Html .Raw(Resources.C1FlexGrid.ColumnsColumnLayout_Text2) </ p > @Html .C1().MultiSelect().Id( "columnPicker" ).DisplayMemberPath( "header" ).CheckedMemberPath( "visible" ).HeaderFormat( "{count:n0} columns visible" ) < br /> < br /> @Html .C1().FlexGrid().Id( "theGrid" ).Bind(Model) < p > @Html .Raw(Resources.C1FlexGrid.ColumnsColumnLayout_Text3) </ p > < button id = "btnSave" class = "btn btn-default" > @Html .Raw(Resources.C1FlexGrid.ColumnsColumnLayout_Text4) </ button > < button id = "btnRestore" class = "btn btn-default" > @Html .Raw(Resources.C1FlexGrid.ColumnsColumnLayout_Text5) </ button > |