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
Italy
Doohickey
Green
4
3
3
-4,908.11
1,296.54
4,419.83
653.14
783.32
0.20
1
2/25/2025
2/25/2025
Greece
Sprocket
White
5
1
1
1,182.85
-853.80
-4,469.64
2,237.89
-21.98
0.05
2
3/25/2025
3/25/2025
Greece
Gadget
Black
5
2
0
-476.93
-1,719.69
2,079.09
-4,149.21
1,097.73
0.18
3
4/25/2025
4/25/2025
Japan
Sprocket
White
3
1
1
3,291.52
-2,500.15
-2,552.48
512.56
-3,612.50
0.21
4
5/25/2025
5/25/2025
Italy
Sprocket
Blue
4
1
4
1,986.00
3,976.01
1,261.44
1,596.88
565.79
0.11
5
6/25/2025
6/25/2025
Germany
Sprocket
White
1
1
1
4,545.47
-4,449.02
360.67
3,144.52
1,831.64
0.15
6
7/25/2025
7/25/2025
Japan
Sprocket
Blue
3
1
4
-1,859.23
3,682.74
-4,696.19
602.21
-1,542.63
0.14
7
8/25/2025
8/25/2025
Greece
Doohickey
Red
5
3
2
-3,972.01
3,051.52
2,197.33
-3,804.91
-4,708.15
0.02
8
9/25/2025
9/25/2025
Germany
Gadget
Green
1
2
3
4,760.53
472.80
-698.74
-1,269.83
-4,432.30
0.19
9
10/25/2025
10/25/2025
US
Widget
Black
0
0
0
4,294.91
4,800.25
-2,820.20
-2,705.68
2,692.44
0.02
10
11/25/2025
11/25/2025
Japan
Widget
White
3
0
1
-4,772.21
-2,101.63
-4,063.84
-1,440.61
1,457.51
0.03
11
12/25/2025
12/25/2025
Japan
Widget
Blue
3
0
4
3,322.05
-3,495.38
-3,511.52
1,734.50
-641.42
0.04
12
1/25/2025
1/25/2025
Japan
Widget
White
3
0
1
-4,281.91
-2,893.58
4,923.90
3,945.47
4,592.98
0.17
13
2/25/2025
2/25/2025
US
Sprocket
White
0
1
1
1,521.96
-4,700.46
4,070.38
-4,206.86
-4,606.87
0.05
14
3/25/2025
3/25/2025
Japan
Doohickey
Black
3
3
0
-866.70
4,123.09
-2,269.78
567.01
-4,500.52
0.23
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 > |