11import React , { useEffect , useRef , useState } from "react" ;
2-
32import ReactDOM from "react-dom/client" ;
4- import "./index.css" ;
5-
6- import { IgrGrid , IgrPaginator , IgrGridModule , GridPagingMode } from "igniteui-react-grids" ;
3+ import { IgrGrid , IgrPaginator , GridPagingMode } from "igniteui-react-grids" ;
74import { IgrColumn } from "igniteui-react-grids" ;
8-
95import "igniteui-react-grids/grids/combined" ;
106import "igniteui-react-grids/grids/themes/light/bootstrap.css" ;
117import { RemoteService } from "./RemotePagingService" ;
128import { CustomersWithPageResponseModel } from "./CustomersWithPageResponseModel" ;
139import { IgrNumberEventArgs } from "igniteui-react" ;
1410
15- IgrGridModule . register ( ) ;
16-
1711export default function App ( ) {
1812 const grid = useRef < IgrGrid > ( null ) ;
1913 const paginator = useRef < IgrPaginator > ( null ) ;
@@ -26,31 +20,26 @@ export default function App() {
2620 } , [ page , perPage ] ) ;
2721
2822 function loadGridData ( pageIndex ?: number , pageSize ?: number ) {
29- // Set loading
3023 grid . current . isLoading = true ;
3124
32- // Fetch data
3325 RemoteService . getDataWithPaging ( pageIndex , pageSize )
3426 . then ( ( response : CustomersWithPageResponseModel ) => {
3527 setData ( response . items ) ;
36- // Stop loading when data is retrieved
3728 grid . current . isLoading = false ;
3829 paginator . current . totalRecords = response . totalRecordsCount ;
3930 } )
4031 . catch ( ( error ) => {
4132 console . error ( error . message ) ;
4233 setData ( [ ] ) ;
43- // Stop loading even if error occurs. Prevents endless loading
4434 grid . current . isLoading = false ;
45-
46- } )
35+ } ) ;
4736 }
4837
49- function onPageNumberChange ( paginator : IgrPaginator , args : IgrNumberEventArgs ) {
38+ function onPageNumberChange ( args : IgrNumberEventArgs ) {
5039 setPage ( args . detail ) ;
5140 }
5241
53- function onPageSizeChange ( paginator : IgrPaginator , args : IgrNumberEventArgs ) {
42+ function onPageSizeChange ( args : IgrNumberEventArgs ) {
5443 setPerPage ( args . detail ) ;
5544 }
5645
@@ -60,29 +49,28 @@ export default function App() {
6049 < IgrGrid
6150 ref = { grid }
6251 data = { data }
63- pagingMode = { GridPagingMode . Remote }
52+ pagingMode = { "remote" }
6453 primaryKey = "customerId"
6554 height = "600px"
6655 >
67- < IgrPaginator
68- perPage = { perPage }
69- ref = { paginator }
70- pageChange = { onPageNumberChange }
71- perPageChange = { onPageSizeChange } >
72- </ IgrPaginator >
56+ < IgrPaginator
57+ perPage = { perPage }
58+ ref = { paginator }
59+ onPageChange = { onPageNumberChange }
60+ onPerPageChange = { onPageSizeChange }
61+ > </ IgrPaginator >
7362 < IgrColumn field = "customerId" hidden = { true } > </ IgrColumn >
7463 < IgrColumn field = "companyName" header = "Company Name" > </ IgrColumn >
7564 < IgrColumn field = "contactName" header = "Contact Name" > </ IgrColumn >
7665 < IgrColumn field = "contactTitle" header = "Contact Title" > </ IgrColumn >
7766 < IgrColumn field = "address.country" header = "Country" > </ IgrColumn >
7867 < IgrColumn field = "address.phone" header = "Phone" > </ IgrColumn >
7968 </ IgrGrid >
80-
8169 </ div >
8270 </ div >
8371 ) ;
8472}
8573
86- // rendering above component in the React DOM
74+ // Render the component
8775const root = ReactDOM . createRoot ( document . getElementById ( "root" ) ) ;
8876root . render ( < App /> ) ;
0 commit comments