FlexGrid
FlexGrid
Column Picker
This sample shows how to implement a column-picker for FlexGrid.
Features
ID
Start
End
Country
Product
Color
Amount
Amount2
Discount
Active
Url
Img
Rank
ID
Start
End
Country
Product
Color
Amount
Amount2
Discount
Active
Url
Img
Rank
1
1/25/2025
1/25/2025
US
Gadget
Red
-2,587.64
2,811.82
0.09
https://en.wikipedia.org/wiki/Tourism_in_US
https://cdn.grapecity.com/wijmo/images/1.png
1
2
2/25/2025
2/25/2025
Canada
Widget
Red
3,195.89
3,713.24
0.06
https://en.wikipedia.org/wiki/Tourism_in_Canada
https://cdn.grapecity.com/wijmo/images/2.png
3
3
3/25/2025
3/25/2025
German
Widget
White
2,313.31
1,820.51
0
https://en.wikipedia.org/wiki/Tourism_in_German
https://cdn.grapecity.com/wijmo/images/3.png
3
4
4/25/2025
4/25/2025
Italy
Gadget
Black
-3,193.81
1,565.20
0.17
https://en.wikipedia.org/wiki/Tourism_in_Italy
https://cdn.grapecity.com/wijmo/images/4.png
3
5
5/25/2025
5/25/2025
US
Gadget
Green
1,992.89
573.93
0.24
https://en.wikipedia.org/wiki/Tourism_in_US
https://cdn.grapecity.com/wijmo/images/1.png
3
6
6/25/2025
6/25/2025
Korea
Gadget
White
-2,311.22
3,514.34
0.12
https://en.wikipedia.org/wiki/Tourism_in_Korea
https://cdn.grapecity.com/wijmo/images/2.png
1
7
7/25/2025
7/25/2025
China
Gadget
Black
201.09
2,080.39
0.15
https://en.wikipedia.org/wiki/Tourism_in_China
https://cdn.grapecity.com/wijmo/images/3.png
5
8
8/25/2025
8/25/2025
US
Widget
Black
2,042.44
3,005.04
0.02
https://en.wikipedia.org/wiki/Tourism_in_US
https://cdn.grapecity.com/wijmo/images/4.png
5
9
9/25/2025
9/25/2025
France
Widget
Green
2,813.06
4,125.22
0.23
https://en.wikipedia.org/wiki/Tourism_in_France
https://cdn.grapecity.com/wijmo/images/1.png
5
10
10/25/2025
10/25/2025
Japan
Gadget
White
-3,239.35
2,122.54
0.01
https://en.wikipedia.org/wiki/Tourism_in_Japan
https://cdn.grapecity.com/wijmo/images/2.png
5
11
11/25/2025
11/25/2025
Canada
Gadget
White
3,444.62
86.37
0.14
https://en.wikipedia.org/wiki/Tourism_in_Canada
https://cdn.grapecity.com/wijmo/images/3.png
2
12
12/25/2025
12/25/2025
German
Widget
Black
-3,247.41
3,393.65
0.25
https://en.wikipedia.org/wiki/Tourism_in_German
https://cdn.grapecity.com/wijmo/images/4.png
1
13
1/25/2025
1/25/2025
Korea
Widget
Red
1,792.87
2,450.05
0.03
https://en.wikipedia.org/wiki/Tourism_in_Korea
https://cdn.grapecity.com/wijmo/images/1.png
1
14
2/25/2025
2/25/2025
Italy
Widget
White
-3,030.91
1,013.95
0.19
https://en.wikipedia.org/wiki/Tourism_in_Italy
https://cdn.grapecity.com/wijmo/images/2.png
4
15
3/25/2025
3/25/2025
Canada
Gadget
White
-121.49
4,450.30
0.03
https://en.wikipedia.org/wiki/Tourism_in_Canada
https://cdn.grapecity.com/wijmo/images/3.png
3
16
4/25/2025
4/25/2025
Canada
Widget
Red
-1,085.25
361.52
0.09
https://en.wikipedia.org/wiki/Tourism_in_Canada
https://cdn.grapecity.com/wijmo/images/4.png
2
17
5/25/2025
5/25/2025
UK
Widget
White
-3,633.76
1,771.16
0.21
https://en.wikipedia.org/wiki/Tourism_in_UK
https://cdn.grapecity.com/wijmo/images/1.png
3
18
6/25/2025
6/25/2025
UK
Widget
White
3,547.59
2,502.69
0.09
https://en.wikipedia.org/wiki/Tourism_in_UK
https://cdn.grapecity.com/wijmo/images/2.png
1
19
7/25/2025
7/25/2025
China
Gadget
Black
1,670.89
778.90
0.06
https://en.wikipedia.org/wiki/Tourism_in_China
https://cdn.grapecity.com/wijmo/images/3.png
4
20
8/25/2025
8/25/2025
Canada
Widget
Black
2,526.83
797.32
0.05
https://en.wikipedia.org/wiki/Tourism_in_Canada
https://cdn.grapecity.com/wijmo/images/4.png
4
21
9/25/2025
9/25/2025
UK
Widget
Red
2,468.49
788.64
0.08
https://en.wikipedia.org/wiki/Tourism_in_UK
https://cdn.grapecity.com/wijmo/images/1.png
3
22
10/25/2025
10/25/2025
German
Gadget
Black
-4,369.28
1,593.61
0.08
https://en.wikipedia.org/wiki/Tourism_in_German
https://cdn.grapecity.com/wijmo/images/2.png
3
23
11/25/2025
11/25/2025
China
Widget
Black
-4,571.27
1,695.21
0.22
https://en.wikipedia.org/wiki/Tourism_in_China
https://cdn.grapecity.com/wijmo/images/3.png
3
24
12/25/2025
12/25/2025
Japan
Widget
Red
-3,951.78
2,083.58
0.13
https://en.wikipedia.org/wiki/Tourism_in_Japan
https://cdn.grapecity.com/wijmo/images/4.png
4
25
1/25/2025
1/25/2025
US
Widget
Black
-4,441.14
832.59
0.04
https://en.wikipedia.org/wiki/Tourism_in_US
https://cdn.grapecity.com/wijmo/images/1.png
4
26
2/25/2025
2/25/2025
UK
Gadget
Red
-71.63
3,671.35
0.03
https://en.wikipedia.org/wiki/Tourism_in_UK
https://cdn.grapecity.com/wijmo/images/2.png
5
27
3/25/2025
3/25/2025
UK
Gadget
Red
4,479.22
2,078.84
0.21
https://en.wikipedia.org/wiki/Tourism_in_UK
https://cdn.grapecity.com/wijmo/images/3.png
2
28
4/25/2025
4/25/2025
Korea
Gadget
Green
3,725.41
2,328.42
0.09
https://en.wikipedia.org/wiki/Tourism_in_Korea
https://cdn.grapecity.com/wijmo/images/4.png
1
29
5/25/2025
5/25/2025
US
Widget
Black
2,121.58
687.92
0.03
https://en.wikipedia.org/wiki/Tourism_in_US
https://cdn.grapecity.com/wijmo/images/1.png
3
30
6/25/2025
6/25/2025
China
Widget
Green
-4,839.98
4,216.05
0.19
https://en.wikipedia.org/wiki/Tourism_in_China
https://cdn.grapecity.com/wijmo/images/2.png
4
31
7/25/2025
7/25/2025
Italy
Widget
Black
464.71
1,096.94
0.22
https://en.wikipedia.org/wiki/Tourism_in_Italy
https://cdn.grapecity.com/wijmo/images/3.png
5
32
8/25/2025
8/25/2025
Japan
Gadget
Red
4,993.37
530.08
0.10
https://en.wikipedia.org/wiki/Tourism_in_Japan
https://cdn.grapecity.com/wijmo/images/4.png
4
33
9/25/2025
9/25/2025
Italy
Gadget
Green
4,308.05
929.56
0.03
https://en.wikipedia.org/wiki/Tourism_in_Italy
https://cdn.grapecity.com/wijmo/images/1.png
3
34
10/25/2025
10/25/2025
France
Widget
Black
-345.70
3,404.35
0.18
https://en.wikipedia.org/wiki/Tourism_in_France
https://cdn.grapecity.com/wijmo/images/2.png
5
35
11/25/2025
11/25/2025
US
Gadget
Red
2,470.75
1,365.41
0.05
https://en.wikipedia.org/wiki/Tourism_in_US
https://cdn.grapecity.com/wijmo/images/3.png
2
36
12/25/2025
12/25/2025
Korea
Widget
Red
2,974.68
1,451.84
0.09
https://en.wikipedia.org/wiki/Tourism_in_Korea
https://cdn.grapecity.com/wijmo/images/4.png
1
37
1/25/2025
1/25/2025
US
Widget
Green
3,380
743.35
0.02
https://en.wikipedia.org/wiki/Tourism_in_US
https://cdn.grapecity.com/wijmo/images/1.png
3
38
2/25/2025
2/25/2025
UK
Widget
Green
4,198.18
874.65
0.22
https://en.wikipedia.org/wiki/Tourism_in_UK
https://cdn.grapecity.com/wijmo/images/2.png
4
39
3/25/2025
3/25/2025
Canada
Gadget
Green
3,962.13
4,859.84
0.18
https://en.wikipedia.org/wiki/Tourism_in_Canada
https://cdn.grapecity.com/wijmo/images/3.png
4
40
4/25/2025
4/25/2025
France
Gadget
Black
4,486.36
3,443.52
0.06
https://en.wikipedia.org/wiki/Tourism_in_France
https://cdn.grapecity.com/wijmo/images/4.png
5
41
5/25/2025
5/25/2025
US
Widget
Black
-739.31
4,204.48
0.15
https://en.wikipedia.org/wiki/Tourism_in_US
https://cdn.grapecity.com/wijmo/images/1.png
2
42
6/25/2025
6/25/2025
Korea
Widget
Black
-4,337.05
164.47
0.13
https://en.wikipedia.org/wiki/Tourism_in_Korea
https://cdn.grapecity.com/wijmo/images/2.png
1
43
7/25/2025
7/25/2025
UK
Gadget
Black
-1,054.50
1,139.20
0.17
https://en.wikipedia.org/wiki/Tourism_in_UK
https://cdn.grapecity.com/wijmo/images/3.png
2
44
8/25/2025
8/25/2025
UK
Widget
White
1,867.47
1,840.15
0.20
https://en.wikipedia.org/wiki/Tourism_in_UK
https://cdn.grapecity.com/wijmo/images/4.png
5
45
9/25/2025
9/25/2025
China
Gadget
Black
2,508.62
2,784.31
0.13
https://en.wikipedia.org/wiki/Tourism_in_China
https://cdn.grapecity.com/wijmo/images/1.png
1
46
10/25/2025
10/25/2025
German
Gadget
Red
-2,573.47
3,515.47
0.15
https://en.wikipedia.org/wiki/Tourism_in_German
https://cdn.grapecity.com/wijmo/images/2.png
1
47
11/25/2025
11/25/2025
Canada
Widget
White
3,303.90
2,819.65
0.15
https://en.wikipedia.org/wiki/Tourism_in_Canada
https://cdn.grapecity.com/wijmo/images/3.png
1
48
12/25/2025
12/25/2025
France
Gadget
Black
185.33
2,765.45
0.01
https://en.wikipedia.org/wiki/Tourism_in_France
https://cdn.grapecity.com/wijmo/images/4.png
4
49
1/25/2025
1/25/2025
Japan
Widget
Red
-4,897.56
1,150.66
0.08
https://en.wikipedia.org/wiki/Tourism_in_Japan
https://cdn.grapecity.com/wijmo/images/1.png
2
50
2/25/2025
2/25/2025
UK
Gadget
Green
3,858.70
4,709
0.08
https://en.wikipedia.org/wiki/Tourism_in_UK
https://cdn.grapecity.com/wijmo/images/2.png
2

0

Description
This sample shows how to implement a column-picker for FlexGrid.
Click the column-picker icon at the top-left cell to show the column-picker dropdown list where you can select the columns you want to display.
You can also save and restore columns' layout of the FlexGrid. Please try changing columns' layout as you want, click the button 'Save Layout' to save it. Now, you can change columns' layout freely and then can click the button 'Load Layout' to restore the columns' layout which was saved.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | using Microsoft.AspNetCore.Mvc; using MvcExplorer.Models; namespace MvcExplorer.Controllers { public partial class FlexGridController : Controller { public ActionResult ColumnPicker() { var model = Sale.GetData(50); return View(model); } } } |
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | @model IEnumerable< Sale > @section Styles{ < style > .column-picker-icon { cursor: pointer; } .wj-multiselectlistbox.column-picker { box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } .wj-multiselectlistbox .wj-listbox-item > label { display: block; margin: 0 0 3px 0; } .wj-multiselectlistbox .wj-listbox-item.wj-state-selected { background: transparent; color: inherit; } .wj-multiselectlistbox .wj-listbox-item:hover { background: rgba(0,0,0,.05); } .wj-multiselectlistbox .drop-marker { position: absolute; background: #0085c7; opacity: 0.5; pointer-events: none; z-index: 1000; } </ style > } @section Scripts{ <script type="text/javascript"> c1.documentReady( function () { // Create the Column-picker dropdown list var grid = wijmo.Control.getControl( '#gridColumnPicker' ); let theColumnPicker = new wijmo.input.MultiSelectListBox( '#theColumnPicker' , { itemsSource: grid.columns, checkedMemberPath: 'visible' , displayMemberPath: 'header' , showFilterInput: true , showSelectAllCheckbox: true , lostFocus: function () { wijmo.hidePopup(theColumnPicker.hostElement) }, checkedItemsChanged: function (sender) { grid.columns.forEach( function (item) { item.visible = false ; }); sender.checkedItems.forEach( function (item) { grid.columns.getColumn(item.binding).visible = true ; }); } }); // Config drag & drop for the Column-picker configDragDropForColumnPicker(grid, theColumnPicker); // Prepare for column-picker button var tempBtnColPicker = document.getElementById( 'column-picker-icon' ); tempBtnColPicker._columnPicker = theColumnPicker; tempBtnColPicker._grid = grid; }); function formatItem(panel, r, c, cell) { if (panel.cellType == wijmo.grid.CellType.TopLeft) { var tempBtnColPicker = document.getElementById( 'column-picker-icon' ), btnColPicker = tempBtnColPicker.cloneNode( true ), theColumnPicker = tempBtnColPicker._columnPicker, grid = tempBtnColPicker._grid; // Show the column picker when the user clicks at the corner top-left cell btnColPicker.addEventListener( "click" , function (e) { let host = theColumnPicker.hostElement; if (host.offsetHeight) { wijmo.hidePopup(host, true , true ); grid.focus(); } else { wijmo.showPopup(host, e.target, false , true , false ); theColumnPicker.focus(); } e.preventDefault(); }); btnColPicker.addEventListener( "mousedown" , function (e) { e.preventDefault(); e.stopPropagation(); }); cell.appendChild(btnColPicker); if (theColumnPicker.hostElement.style.display != 'none' ) { wijmo.showPopup(theColumnPicker.hostElement, btnColPicker, false , true , false ); } } } // Config Column-picker's drag & drop function configDragDropForColumnPicker(theGrid, theColumnPicker) { var isDragEnabled = false , dragSrc = null , dragDst = null , theColumnPickerListBox = theColumnPicker.listBox, dragCheckbox = document.getElementById( 'enableDrag' ); dragCheckbox.addEventListener( 'click' , function (e) { var element = e.target; isDragEnabled = element. checked ; var host = theColumnPickerListBox.hostElement; var items = host.getElementsByClassName( 'wj-listbox-item' ); for ( var i = 0; i < items.length ; i++) { enableDragItem(items[i], isDragEnabled); } }); theColumnPickerListBox.formatItem.addHandler( function (s, e) { enableDragItem(e.item, isDragEnabled); }); var theColumnPickerHost = theColumnPickerListBox .hostElement; theColumnPickerHost.addEventListener( 'dragstart' , handleDragStart); theColumnPickerHost.addEventListener( 'dragover' , handleDragOver); theColumnPickerHost.addEventListener( 'drop' , handleDrop); theColumnPickerHost.addEventListener( 'dragend' , handleDragEnd); function enableDragItem(item, enabled) { item.setAttribute( 'draggable' , enabled); } function handleDragStart(e) { dragSrc = wijmo .closest(e.target, '.wj-listbox-item' ); if (dragSrc) { e.dataTransfer.setData( 'text' , dragSrc.innerHTML); e.dataTransfer.effectAllowed = 'move' ; } } function handleDragOver(e) { // C1WEB-28851: Fix getting wrong target in IE var target = document .elementFromPoint(e.clientX, e.clientY), dragOver = wijmo .closest(target, '.wj-listbox-item' ); if (dragDst && dragDst !== dragOver) { removeDropMarker(); } if (dragOver && dragOver !== dragSrc) { e.preventDefault(); e.dataTransfer.dropEffect = 'move' ; dragDst = dragOver ; var src = getElementIndex (dragSrc); var dst = getElementIndex (dragDst); removeDropMarker(); addDropMarker(dst > src); } else { dragDst = null ; } } function handleDrop(e) { if (dragSrc && dragDst) { e.preventDefault(); var src = theGrid.getColumn(dragSrc.innerText.trim()).index, dst = theGrid.getColumn(dragDst.innerText.trim()).index; theGrid.columns.moveElement(src, dst); } handleDragEnd(); } function handleDragEnd() { dragSrc = null ; dragDst = null ; removeDropMarker(); } function getElementIndex(element) { var parent = element.parentElement; var siblings = Array.prototype.slice.call(parent.children); return siblings.indexOf(element); } function removeDropMarker() { wijmo.removeChild(wijmo.getElement( '.drop-marker' )); } function addDropMarker(isAfterPos) { const height = 4; const margin = 2; var width = dragDst.clientWidth - margin; var leftPos = margin; var topPos = isAfterPos ? (dragDst.offsetTop + dragDst.clientHeight - height) : (dragDst.offsetTop); // C1WEB-28851: IE does not recornize the code, hence change to this var html = '<div class="drop-marker" style="top:' + topPos + 'px;left:' + leftPos + 'px;height:' + height + 'px;width:' + width + 'px"></div>' ; wijmo.createElement(html, theColumnPicker.hostElement); } } // Save columns' layout to localStorage function saveLayout() { var grid = wijmo.Control.getControl( "#gridColumnPicker" ); localStorage[ 'columns' ] = grid.columnLayout; } // Restore columns' layout from localStorage function loadLayout() { var grid = wijmo.Control.getControl( "#gridColumnPicker" ), columnLayout = localStorage[ 'columns' ]; if (columnLayout) { grid.columnLayout = columnLayout; } } </script> } < c1-flex-grid id = "gridColumnPicker" auto-generate-columns = "true" class = "grid" is-read-only = "true" item-formatter = "formatItem" > < c1-items-source initial-items-count = "100" source-collection = "Model" ></ c1-items-source > </ c1-flex-grid > < div class = "checkbox" > < label > < input id = "enableDrag" type = "checkbox" > @Html .Raw(FlexGridRes.ColumnPicker_Text2) </ label > </ div > < div style = "display:none" > < img id = "column-picker-icon" class = "column-picker-icon" src = "~/Content/images/icons/Columns.png" width = "20" height = "20" /> < div id = "theColumnPicker" class = "column-picker" style = "display:none" ></ div > </ div > < input type = "button" value = "@FlexGridRes.ColumnPicker_Text4" class = "btn" onclick = "saveLayout()" /> < input type = "button" value = "@FlexGridRes.ColumnPicker_Text5" class = "btn" onclick = "loadLayout()" /> @section Summary{ < p > @Html .Raw(FlexGridRes.ColumnPicker_Text0)</ p > } @section Description{ < p > @Html .Raw(FlexGridRes.ColumnPicker_Text0)</ p > < p > @Html .Raw(FlexGridRes.ColumnPicker_Text1)</ p > < p > @Html .Raw(FlexGridRes.ColumnPicker_Text3)</ p > } |