@@ -2,35 +2,26 @@ import React, { useEffect, useRef, useState } from 'react';
2
2
import ReactDOM from 'react-dom/client' ;
3
3
4
4
import {
5
- FilterMode ,
6
5
IgrActionStrip ,
7
6
IgrGrid ,
8
7
IgrColumn ,
9
- IgrGridModule ,
10
8
IgrGridPinningActions ,
11
9
IgrGridToolbar ,
12
10
IgrGridToolbarActions ,
13
11
IgrGridToolbarHiding ,
14
12
IgrGridToolbarPinning ,
15
13
IgrPaginator ,
16
14
IgrGridState ,
17
- IgrGridStateOptions ,
18
- GridSelectionMode
15
+ IgrGridStateOptions
19
16
} from 'igniteui-react-grids' ;
20
- import { IgrButton , IgrCheckbox , IgrCheckboxModule , IgrCheckboxChangeEventArgs , IgrIcon , IgrIconModule } from 'igniteui-react' ;
17
+ import { IgrButton , IgrCheckbox , IgrCheckboxChangeEventArgs , IgrIcon } from 'igniteui-react' ;
21
18
import { registerIconFromText } from 'igniteui-webcomponents' ;
22
19
import { CustomersData } from './CustomersData' ;
23
20
24
21
import 'igniteui-react-grids/grids/combined' ;
25
22
import 'igniteui-react-grids/grids/themes/light/bootstrap.css' ;
26
23
import './index.css' ;
27
24
28
- const mods : any [ ] = [
29
- IgrGridModule ,
30
- IgrIconModule ,
31
- IgrCheckboxModule
32
- ] ;
33
- mods . forEach ( ( m ) => m . register ( ) ) ;
34
25
35
26
const restoreIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M480-120q-138 0-240.5-91.5T122-440h82q14 104 92.5 172T480-200q117 0 198.5-81.5T760-480q0-117-81.5-198.5T480-760q-69 0-129 32t-101 88h110v80H120v-240h80v94q51-64 124.5-99T480-840q75 0 140.5 28.5t114 77q48.5 48.5 77 114T840-480q0 75-28.5 140.5t-77 114q-48.5 48.5-114 77T480-120Zm112-192L440-464v-216h80v184l128 128-56 56Z"/></svg>' ;
36
27
const saveIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm2 16H5V5h11.17L19 7.83V19zm-7-7c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3zM6 6h9v4H6z"/></svg>' ;
@@ -41,6 +32,8 @@ const refreshIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox
41
32
42
33
export default function App ( ) {
43
34
const gridData = new CustomersData ( ) ;
35
+ const stateKey = "grid-state" ;
36
+
44
37
const [ allOptions , setAllOptions ] = useState ( true ) ;
45
38
const [ options , setOption ] = useState < IgrGridStateOptions > ( {
46
39
cellSelection : true ,
@@ -55,14 +48,15 @@ export default function App() {
55
48
rowPinning : true ,
56
49
columnSelection : true
57
50
} ) ;
51
+ const [ page , setPage ] = useState < number > ( 0 ) ;
52
+ const [ perPage , setPerPage ] = useState < number > ( 15 ) ;
53
+ const [ totalRecords , setTotalRecords ] = useState < number > ( gridData . length ) ;
58
54
59
55
let grid : IgrGrid ;
60
- function gridRef ( ref : IgrGrid ) {
56
+ const gridRef = ( ref : IgrGrid ) => {
61
57
grid = ref ;
62
- }
63
- let paginatorRef = useRef < IgrPaginator > ( null ) ;
64
- const stateKey = "grid-state" ;
65
- let gridStateRef = useRef < IgrGridState > ( null ) ;
58
+ } ;
59
+ const gridStateRef = useRef < IgrGridState > ( null ) ;
66
60
67
61
useEffect ( ( ) => {
68
62
registerIconFromText ( "restore" , restoreIcon , "material" ) ;
@@ -79,65 +73,69 @@ export default function App() {
79
73
} ;
80
74
} , [ ] ) ;
81
75
82
- function saveGridState ( ) {
76
+ const saveGridState = ( ) => {
83
77
const state = gridStateRef . current . getStateAsString ( [ ] ) ;
84
78
window . localStorage . setItem ( stateKey , state ) ;
85
79
}
86
80
87
- function restoreGridState ( ) {
81
+ const restoreGridState = ( ) => {
88
82
const state = window . localStorage . getItem ( stateKey ) ;
89
83
if ( state ) {
90
84
gridStateRef . current . applyStateFromString ( state , [ ] ) ;
91
85
}
92
86
}
93
87
94
- function resetGridState ( ) {
95
- paginatorRef . current . page = 0 ;
96
- paginatorRef . current . perPage = 15 ;
97
- paginatorRef . current . totalRecords = gridData . length ;
98
- grid . clearFilter ( null ) ;
88
+ const resetGridState = ( ) => {
89
+ setPage ( 0 ) ;
90
+ setPerPage ( 15 ) ;
91
+ setTotalRecords ( gridData . length ) ;
92
+
93
+ grid . clearFilter ( ) ;
99
94
grid . sortingExpressions = [ ] ;
100
95
grid . groupingExpressions = [ ] ;
101
96
grid . deselectAllColumns ( ) ;
102
97
grid . deselectAllRows ( ) ;
103
98
grid . clearCellSelection ( ) ;
104
99
}
105
100
106
- function onChange ( e : IgrCheckboxChangeEventArgs ) {
101
+ const onChange = ( e : IgrCheckboxChangeEventArgs ) => {
107
102
const s = e . target as IgrCheckbox ;
103
+
108
104
if ( s . name === 'allFeatures' ) {
109
- const bEnabled = e . detail . checked ;
105
+ const isChecked = e . detail . checked ;
106
+
107
+ setAllOptions ( isChecked ) ;
108
+
110
109
setOption ( {
111
- cellSelection : bEnabled ,
112
- rowSelection : bEnabled ,
113
- filtering : bEnabled ,
114
- advancedFiltering : bEnabled ,
115
- paging : bEnabled ,
116
- sorting : bEnabled ,
117
- groupBy : bEnabled ,
118
- columns : bEnabled ,
119
- expansion : bEnabled ,
120
- rowPinning : bEnabled ,
121
- columnSelection : bEnabled
110
+ cellSelection : isChecked ,
111
+ rowSelection : isChecked ,
112
+ filtering : isChecked ,
113
+ advancedFiltering : isChecked ,
114
+ paging : isChecked ,
115
+ sorting : isChecked ,
116
+ groupBy : isChecked ,
117
+ columns : isChecked ,
118
+ expansion : isChecked ,
119
+ rowPinning : isChecked ,
120
+ columnSelection : isChecked
122
121
} ) ;
123
- for ( const key of Object . keys ( options ) ) {
124
- gridStateRef . current . options [ key ] = bEnabled ;
125
- }
126
122
} else {
127
- gridStateRef . current . options [ s . name ] = e . detail . checked ;
123
+ const newOptions = { ...options } ;
124
+ newOptions [ s . name as keyof typeof newOptions ] = e . detail . checked ;
125
+ setOption ( newOptions ) ;
128
126
}
129
127
}
130
128
131
- function leavePage ( ) {
129
+ const leavePage = ( ) => {
132
130
saveGridState ( ) ;
133
131
window . location . replace ( "./grids/grid/state-persistence-about" ) ;
134
132
}
135
133
136
- function clearStorage ( ) {
134
+ const clearStorage = ( ) => {
137
135
window . localStorage . removeItem ( stateKey ) ;
138
136
}
139
137
140
- function reloadPage ( ) {
138
+ const reloadPage = ( ) => {
141
139
window . location . reload ( ) ;
142
140
}
143
141
@@ -191,7 +189,7 @@ export default function App() {
191
189
< IgrCheckbox name = "groupBy" onChange = { onChange } checked = { options . groupBy } > < span > Group By</ span > </ IgrCheckbox >
192
190
</ div >
193
191
< IgrGrid ref = { gridRef } data = { gridData } primaryKey = "ID" width = "95%" height = "500px" autoGenerate = { false } moving = { true } allowFiltering = { true }
194
- allowAdvancedFiltering = { true } filterMode = { FilterMode . ExcelStyleFilter } columnSelection = { GridSelectionMode . Multiple } rowSelection = { GridSelectionMode . Multiple } >
192
+ allowAdvancedFiltering = { true } filterMode = "excelStyleFilter" columnSelection = "multiple" rowSelection = "multiple" >
195
193
< IgrGridState ref = { gridStateRef } > </ IgrGridState >
196
194
< IgrGridToolbar >
197
195
< IgrGridToolbarActions >
@@ -202,7 +200,13 @@ export default function App() {
202
200
< IgrActionStrip >
203
201
< IgrGridPinningActions > </ IgrGridPinningActions >
204
202
</ IgrActionStrip >
205
- < IgrPaginator ref = { paginatorRef } > </ IgrPaginator >
203
+ < IgrPaginator
204
+ page = { page }
205
+ perPage = { perPage }
206
+ totalRecords = { totalRecords }
207
+ onPageChange = { ( ev ) => setPage ( ev . detail ) }
208
+ onPerPageChange = { ( ev ) => setPerPage ( ev . detail ) } >
209
+ </ IgrPaginator >
206
210
207
211
< IgrColumn field = "ID" width = "100px" sortable = { true } filterable = { true } pinned = { true } > </ IgrColumn >
208
212
< IgrColumn field = "ContactName" header = "Contact Name" minWidth = "200px" sortable = { true } filterable = { true } pinned = { true } > </ IgrColumn >
0 commit comments