Rath Components
React wrappers around @mui/x-data-grid-premium that ship sensible defaults for fetching, pagination, sorting, filtering, and toolbar wiring. Works in client-side React 18+ apps and Next.js 13+ server components.
Installation
Install the package alongside MUI and Emotion:
npm install @tranz-rath/components @mui/material @mui/x-data-grid-premium @emotion/react @emotion/styled
Peer dependencies: react, react-dom, and (optionally) next when using the server grid in Next.js.
ClientDataGrid
Client-side grid that can render provided rows or fetch them on mount.
import { ClientDataGrid } from "@tranz-rath/components";
const columns = [
{ field: "id", headerName: "ID", width: 80 },
{ field: "name", headerName: "Name", flex: 1 },
];
export default function UsersGrid() {
return (
<ClientDataGrid
apiUrl="/api/users" // omit to use the `rows` prop instead
dataPath="data.items" // where rows live in the JSON (default: "data")
columns={columns} // optional; inferred from the first row if missing
pageSizeOptions={[10, 25, 50]}
showToolbar // enables quick filter + toolbar
onFetchSuccess={(rows, payload) => console.log(rows.length)}
/>
);
}
Key props:
apiUrl: When set (androwsis undefined) the grid fetches JSON on mount.requestInit: Extrafetchoptions (headers, method, etc.).dataPath: Dot path inside the JSON to locate the rows; falls back to common keys (data,rows,items,results).transformResponse(payload): Custom mapper that must return an array of rows.getRowId: Provide if rows do not includeid; otherwise indexes are used.slots/slotProps: Passed directly toDataGridPremium; toolbar shows quick filter by default.
ServerDataGrid
Server-mode grid that streams rows through the MUI dataSource API and can sync URL query params for deep-linkable states.
import { ServerDataGrid } from "@tranz-rath/components";
const columns = [
{ field: "name", headerName: "Name", flex: 1 },
{ field: "role", headerName: "Role", flex: 1 },
];
export default function UsersGrid() {
return (
<ServerDataGrid
apiUrl="/api/users"
columns={columns}
rowCountPath="meta.total" // where total count lives (optional)
dataPath="data" // where rows live (default: "data")
pageSizeOptions={[10, 25, 50, 100]}
syncQueryParams // keep page/sort/filter in the URL (default: true)
buildQueryParams={(params) => {
// params = { paginationModel, sortModel, filterModel, start, end }
return {
start: params.start,
end: params.end,
sortColumn: params.sortModel?.[0]?.field,
sortDirection: params.sortModel?.[0]?.sort,
search: params.filterModel?.quickFilterValues?.join(" "),
};
}}
/>
);
}
Default query behavior (when buildQueryParams is not provided):
- Pagination:
pageandpageSize(0-based page index). - Sorting:
sortColumn+sortDirection(asc/desc). - Filtering: single
filterColumn,filterOperator,filterValueper filter item. - Quick filter:
search.
Response handling:
- Rows are read from
dataPath(defaults todata), or fromdata,rows,items, orresults. - Total row count is read from
rowCountPath, or fromrowCount,total,totalCount,count, orpagination.total. - Override with
transformResponse(payload, params)returning{ rows, rowCount? }.
URL synchronization:
- Controlled by
syncQueryParams(defaulttrue); capturespage,pageSize,sortField,sortDir,filters(JSON), andsearch. - Controlled models (
paginationModel,sortModel,filterModel) are respected and still update the URL unlesssyncQueryParamsisfalse.
Styling:
sxmerges with a default bordered layout.slots/slotPropsare passed through; toolbar quick filter is enabled by default.
Local development
The package ships compiled ESM; no build step is required here. To test locally in an app:
- Run
npm packin this repo. - In your app, install the tarball (
npm install ../rath-components-*.tgz) and import the components.