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
UK
Widget
Red
2
0
2
-2,915.45
4,819.41
-109.22
-2,440.30
-4,724.41
0.01
1
2/25/2025
2/25/2025
Greece
Sprocket
Black
5
1
0
-2,424.04
-2,428.33
-4,125.74
-391.24
3,552.21
0.15
2
3/25/2025
3/25/2025
UK
Doohickey
Green
2
3
3
-188.67
4,183.60
-2,788.93
-4,246.10
-2,508.00
0.23
3
4/25/2025
4/25/2025
UK
Sprocket
Blue
2
1
4
4,593.25
2,558.32
-1,378.38
-4,616.12
-3,257.47
0.06
4
5/25/2025
5/25/2025
UK
Doohickey
White
2
3
1
4,120.56
-4,017.24
112.98
2,282.60
-988.87
0.23
5
6/25/2025
6/25/2025
US
Widget
White
0
0
1
-35.95
-3,856.18
1,490.05
4,846.87
4,086.89
0.12
6
7/25/2025
7/25/2025
Greece
Gadget
Blue
5
2
4
-286.45
4,866.35
1,996.41
-864.00
1,292.27
0.10
7
8/25/2025
8/25/2025
Japan
Gadget
Black
3
2
0
1,575.62
3,101.51
-1,480.96
-2,332.25
383.79
0.21
8
9/25/2025
9/25/2025
Greece
Gadget
Red
5
2
2
2,137.23
4,436.33
-1,087.98
-1,504.94
2,444.12
0.03
9
10/25/2025
10/25/2025
UK
Doohickey
Blue
2
3
4
2,636.15
2,853.85
-4,089.69
-2,223.31
-3,507.25
0.05
10
11/25/2025
11/25/2025
Italy
Sprocket
Black
4
1
0
826.14
1,215.66
4,345.81
1,748.42
2,766.83
0.24
11
12/25/2025
12/25/2025
US
Gadget
Blue
0
2
4
-887.68
292.42
4,370.83
4,413.91
4,698.68
0.16
12
1/25/2025
1/25/2025
UK
Widget
Blue
2
0
4
-1,273.14
919.19
2,333.29
-3,981.79
-1,130.33
0.01
13
2/25/2025
2/25/2025
Germany
Doohickey
Red
1
3
2
3,907.94
-1,530.98
-3,771.19
3,103.96
-1,294.97
0.04
14
3/25/2025
3/25/2025
Germany
Sprocket
Red
1
1
2
-130.04
-1,688.94
-4,146.69
-185.72
4,855.24
0.03

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>