A light datagrid build upon react-table-plain for React in a Material-UI theme.
npm install @dccs/react-datagrid-muionLoadData callback, that returns the data as a Promise<{data: any[], total: number}> (paging needs total to provide the maximal number pages).
javascript
import { DataGridMui } from "@dccs/react-datagrid-mui";
colDef={[
{ prop: "id", header: "Id" },
{ prop: "display_name", header: "Full name", sortable: true }
]}
onLoadData={(page, rowsPerPage, orderBy, desc) =>
fetch(url / with querystring params /)
.then(resp => resp.json())
.then(resp => ({ data: resp.data, total: resp.total }))
}
/>;
`
$3
`javascript
import { DataGridPlain } from "@dccs/react-datagrid-plain";
import { datagridMuiTheme } from "@dccs/react-datagrid-mui";
{...datagridMuiTheme}
colDef={[
{ prop: "id", header: "Id" },
{ prop: "display_name", header: "Full name", sortable: true }
]}
onLoadData={(page, rowsPerPage, orderBy, desc) =>
fetch(url / with querystring params /)
.then(resp => resp.json())
.then(resp => ({ data: resp.data, total: resp.total }))
}
/>;
`
TODO: Codesandbox
$3
`javascript
import { DataGridMui } from "@dccs/react-datagrid-mui";
colDef={[
{ prop: "id", header: "Id" },
{ prop: "display_name", header: "Full name", sortable: true }
]}
onLoadData={(page, rowsPerPage, orderBy, desc) =>
fetch(url / with querystring params /)
.then(resp => resp.json())
.then(resp => ({ data: resp.data, total: resp.total }))
}
/>;
`

or with sorting

Inside the onLoadData you can use whatever Http library you want. That way it is possible to append i.e. authorization tokens, custom http headers, ...
onLoadData can provide data from every source. Server, client, rest, GraphQL, ... react-datagrid-mui does not care.
$3
react-datagrid-mui keeps the state of the table (current page, number of displayes rows, ...) internal, so you don't have to worry about the state.
But that also means that react-datagrid-mui triggers any (re-)load of the data itself. If you want to reload the datagrid from outside you must grap the datagrid instance with a ref and call load() on it.
`javascript
import { DataGridMui } from "@dccs/react-datagrid-mui";
class Example extends React.Component {
datagrid = null;
render() {
return (
colDef={[
{ prop: "id", header: "Id" },
{ prop: "display_name", header: "Full name", sortable: true }
]}
onLoadData={createLoader(url)}
ref={r => (this.datagrid = r)}
/>
);
}
}
``