-
Notifications
You must be signed in to change notification settings - Fork 6
Remote data operations samples update to 19 #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6354bb6
b734ed2
606dd61
4cf2f7b
c519d03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
import React, { useEffect, useRef, useState } from "react"; | ||
|
||
import { useEffect, useRef, useState } from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import "./index.css"; | ||
|
||
import { IgrGrid, IgrPaginator, IgrGridModule, GridPagingMode } from "igniteui-react-grids"; | ||
import { IgrColumn } from "igniteui-react-grids"; | ||
|
||
import "igniteui-react-grids/grids/combined"; | ||
import { IgrColumn, IgrGrid, IgrPaginator } from "igniteui-react-grids"; | ||
import "igniteui-react-grids/grids/themes/light/bootstrap.css"; | ||
import { RemoteService } from "./RemotePagingService"; | ||
import { CustomersWithPageResponseModel } from "./CustomersWithPageResponseModel"; | ||
import { IgrNumberEventArgs } from "igniteui-react"; | ||
|
||
IgrGridModule.register(); | ||
|
||
export default function App() { | ||
const grid = useRef<IgrGrid>(null); | ||
const paginator = useRef<IgrPaginator>(null); | ||
Comment on lines
10
to
11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also in general, refrain from manipulating state through refs - if you're seeing |
||
|
@@ -26,31 +18,26 @@ export default function App() { | |
}, [page, perPage]); | ||
|
||
function loadGridData(pageIndex?: number, pageSize?: number) { | ||
// Set loading | ||
grid.current.isLoading = true; | ||
|
||
// Fetch data | ||
RemoteService.getDataWithPaging(pageIndex, pageSize) | ||
.then((response: CustomersWithPageResponseModel) => { | ||
setData(response.items); | ||
// Stop loading when data is retrieved | ||
grid.current.isLoading = false; | ||
paginator.current.totalRecords = response.totalRecordsCount; | ||
}) | ||
.catch((error) => { | ||
console.error(error.message); | ||
setData([]); | ||
// Stop loading even if error occurs. Prevents endless loading | ||
grid.current.isLoading = false; | ||
|
||
}) | ||
}); | ||
} | ||
|
||
function onPageNumberChange(paginator: IgrPaginator, args: IgrNumberEventArgs) { | ||
function onPageNumberChange(args: IgrNumberEventArgs) { | ||
setPage(args.detail); | ||
} | ||
|
||
function onPageSizeChange(paginator: IgrPaginator, args: IgrNumberEventArgs) { | ||
function onPageSizeChange(args: IgrNumberEventArgs) { | ||
setPerPage(args.detail); | ||
} | ||
|
||
|
@@ -60,29 +47,28 @@ export default function App() { | |
<IgrGrid | ||
ref={grid} | ||
data={data} | ||
pagingMode={GridPagingMode.Remote} | ||
pagingMode={"remote"} | ||
primaryKey="customerId" | ||
height="600px" | ||
> | ||
<IgrPaginator | ||
perPage={perPage} | ||
ref={paginator} | ||
pageChange={onPageNumberChange} | ||
perPageChange={onPageSizeChange}> | ||
</IgrPaginator> | ||
<IgrPaginator | ||
perPage={perPage} | ||
ref={paginator} | ||
onPageChange={onPageNumberChange} | ||
onPerPageChange={onPageSizeChange} | ||
></IgrPaginator> | ||
<IgrColumn field="customerId" hidden={true}></IgrColumn> | ||
<IgrColumn field="companyName" header="Company Name"></IgrColumn> | ||
<IgrColumn field="contactName" header="Contact Name"></IgrColumn> | ||
<IgrColumn field="contactTitle" header="Contact Title"></IgrColumn> | ||
<IgrColumn field="address.country" header="Country"></IgrColumn> | ||
<IgrColumn field="address.phone" header="Phone"></IgrColumn> | ||
</IgrGrid> | ||
|
||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
// rendering above component in the React DOM | ||
// Render the component | ||
const root = ReactDOM.createRoot(document.getElementById("root")); | ||
root.render(<App />); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and
IgrForOfStateEventArgs
isn't imported, possibly typo on the unused IgrForOfState import? If so, you can change the import name