Popup Column Picker
You can easily implement a column-picker UI by using the grid's columns property, a ListBox control, and C1 MVC's showPopup and hidePopup methods.
For example, the grid below loads with an auto-generated set of columns. Click the gear icon at the top-left cell to show a ListBox where you can select the columns you want to display.
Id
Start
End
Country
Product
Color
Country Id
Product Id
Color Id
Amount1
Amount2
Amount3
Amount4
Amount5
Discount
Active
0
1/25/2025
1/25/2025
Japan
Gadget
Blue
3
2
4
-4,024.87
3,588.16
4,292.32
-2,312.30
1,410.81
0.25
1
2/25/2025
2/25/2025
Japan
Widget
Blue
3
0
4
170.31
-980.86
-983.21
-215.52
-4,165.01
0.14
2
3/25/2025
3/25/2025
Greece
Gadget
White
5
2
1
-3,234.13
-3,088.85
-641.32
4,661.74
-2,200.06
0.07
3
4/25/2025
4/25/2025
US
Sprocket
Blue
0
1
4
2,917.73
-4,849.87
-409.92
89.47
-2,553.93
0.13
4
5/25/2025
5/25/2025
Greece
Widget
Blue
5
0
4
-654.74
-4,987.17
-4,148.05
-1,459.43
-381.08
0.06
5
6/25/2025
6/25/2025
Japan
Widget
White
3
0
1
147.55
-2,968.83
4,278.91
3,878.46
-4,982.28
0.02
6
7/25/2025
7/25/2025
UK
Widget
Red
2
0
2
-3,782.43
386.77
1,183.55
-4,683.56
-2,878.90
0.24
7
8/25/2025
8/25/2025
UK
Doohickey
Green
2
3
3
1,431.12
-4,659.63
638.25
-4,458.81
-1,254.07
0.04
8
9/25/2025
9/25/2025
Greece
Gadget
Red
5
2
2
-713.48
4,720.06
-3,851.55
-3,164.22
-1,334.05
0.06
9
10/25/2025
10/25/2025
UK
Sprocket
Green
2
1
3
-3,243.19
2,069.95
-4,354.23
614.90
3,888.11
0.10
10
11/25/2025
11/25/2025
Greece
Gadget
Blue
5
2
4
4,434.41
-1,677.71
-733.16
2,769.80
780.17
0.07
11
12/25/2025
12/25/2025
US
Sprocket
Black
0
1
0
-649.99
2,456.10
4,197.34
1,088.29
1,146.72
0.11
12
1/25/2025
1/25/2025
Italy
Widget
Green
4
0
3
-4,401.93
372.49
-3,436.11
-382.83
4,550.66
0.16
13
2/25/2025
2/25/2025
Italy
Sprocket
Red
4
1
2
-2,704.51
434.63
1,549.68
2,016.26
1,830.90
0.21
14
3/25/2025
3/25/2025
US
Doohickey
Blue
0
3
4
4,552.12
-4,966.50
4,069.79
-279.54
2,779.97
0.10
Id
Start
End
Country
Product
Color
Country Id
Product Id
Color Id
Amount1
Amount2
Amount3
Amount4
Amount5
Discount
Active
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | // This file locates: "Scripts/Lesson/C1Mvc/WijmoShowPopup.js". c1.documentReady(function () { // generate some random data var data = [], countries = [ 'US' , 'Germany' , 'UK' , 'Japan' , 'Italy' , 'Greece' ], products = [ 'Widget' , 'Sprocket' , 'Gadget' , 'Doohickey' ], colors = [ 'Black' , 'White' , 'Red' , 'Green' , 'Blue' ], dt = new Date(); for (var i = 0; i < 100; i++) { var date = new Date(dt.getFullYear(), i % 12, 25, i % 24, i % 60, i % 60), countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length), colorId = Math.floor(Math.random() * colors.length); var item = { id: i, start: date, end: date, country: countries[countryId], product: products[productId], color: colors[colorId], countryId: countryId, productId: productId, colorId: colorId, amount1: Math.random() * 10000 - 5000, amount2: Math.random() * 10000 - 5000, amount3: Math.random() * 10000 - 5000, amount4: Math.random() * 10000 - 5000, amount5: Math.random() * 10000 - 5000, discount: Math.random() / 4, active: i % 4 == 0 }; data.push(item); } var theGrid = wijmo.Control.getControl( '#theGrid' ); theGrid.itemsSource = data; theGrid.formatItem.addHandler(function (s, e) { if (e.panel == s.topLeftCells) { e.cell.innerHTML = '<span class="column-picker-icon glyphicon glyphicon-cog"></span>' ; } }); var theColumnPicker = wijmo.Control.getControl( '#theColumnPicker' ); theColumnPicker.initialize({ itemsSource: theGrid.columns, checkedMemberPath: 'visible' , displayMemberPath: 'header' , lostFocus: function () { wijmo.hidePopup(theColumnPicker.hostElement); } }); // show the column picker when the user clicks the top-left cell var ref = theGrid.hostElement.querySelector( '.wj-topleft' ); ref .addEventListener( 'mousedown' , function (e) { if (wijmo.hasClass(e.target, 'column-picker-icon' )) { wijmo.showPopup(theColumnPicker.hostElement, ref , false , true , false ); theColumnPicker.focus(); e.preventDefault(); } }); // 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 | // This file locates: "Content/css/Lesson/C1Mvc/WijmoShowPopup.css". .column-picker { columns: 3; padding: 12px; margin-left: 12px; margin-top: 26px; box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } .column-picker-icon { cursor: pointer; color: #FF8754; margin: 3px; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Web.Mvc; namespace LearnMvcClient.Controllers { public partial class C1MvcController : Controller { // GET: WijmoShowPopup public ActionResult WijmoShowPopup() { return View(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | < h1 > @Html .Raw(Resources.C1Mvc.WijmoShowPopup_Title) </ h1 > < p > @Html .Raw(Resources.C1Mvc.WijmoShowPopup_Text1) </ p > < p > @Html .Raw(Resources.C1Mvc.WijmoShowPopup_Text2) </ p > @Html .C1().FlexGrid().Id( "theGrid" ).Height(300) < div style = "display:none" > @Html .C1().ListBox().Id( "theColumnPicker" ).CssClass( "column-picker" ) </ div > < p > @Html .Raw(Resources.C1Mvc.WijmoShowPopup_Text3) </ p > < button id = "btnSave" class = "btn btn-default" > @Html .Raw(Resources.C1Mvc.WijmoShowPopup_Text4) </ button > < button id = "btnRestore" class = "btn btn-default" > @Html .Raw(Resources.C1Mvc.WijmoShowPopup_Text5) </ button > |