A modular table, based on a CSS grid layout, optimized for fast configuration and deep customization.
Supported features:
Live Demo

npm i @nadavshaar/react-grid-table
By default, the table is fully featured even with just a basic configuration of rows and columns.
Example:
import React from "react";
import GridTable from '@nadavshaar/react-grid-table';
// custom cell component
const Username = ({ tableManager, value, field, data, column, colIndex, rowIndex }) => {
return (
<img src={data.avatar} alt="user avatar" />
<span className='rgt-text-truncate' style={{marginLeft: 10}}>{value}</span>
)
}
const rows = [
{
"id": 1,
"username": "wotham0",
"gender": "Male",
"last_visited": "12/08/2019",
"test": {"x": 1, "y": 2},
"avatar":"https://robohash.org/atquenihillaboriosam.bmp?size=32x32&set=set1"
},
{
"id": 2,
"username": "dbraddon2",
"gender": "Female",
"last_visited": "16/07/2018",
"test": {"x": 3, "y": 4},
"avatar":"https://robohash.org/etsedex.bmp?size=32x32&set=set1"
},
{
"id": 3,
"username": "dridett3",
"gender": "Male",
"last_visited": "20/11/2016",
"test": {"x": 5, "y": 8},
"avatar":"https://robohash.org/inimpeditquam.bmp?size=32x32&set=set1"
},
{
"id": 4,
"username": "gdefty6",
"gender": "Female",
"last_visited": "03/08/2019",
"test": {"x": 7, "y": 4},
"avatar":"https://robohash.org/nobisducimussaepe.bmp?size=32x32&set=set1"
},
{
"id": 5,
"username": "hbeyer9",
"gender": "Male",
"last_visited": "10/10/2016",
"test": {"x": 2, "y": 2},
"avatar":"https://robohash.org/etconsequatureaque.jpg?size=32x32&set=set1"
}
];
const columns = [
{
id: 1,
field: 'username',
label: 'Username',
cellRenderer: Username,
},
{
id: 2,
field: 'gender',
label: 'Gender',
},
{
id: 3,
field: 'last_visited',
label: 'Last Visited',
sort: ({ a, b, isAscending }) => {
let aa = a.split('/').reverse().join(),
bb = b.split('/').reverse().join();
return aa < bb ? isAscending ? -1 : 1 : (aa > bb ? isAscending ? 1 : -1 : 0);
}
},
{
id: 4,
field: 'test',
label: 'Score',
getValue: ({ value }) => value.x + value.y
}
];
const MyAwesomeTable = () => <GridTable columns={columns} rows={rows} />;
export default MyAwesomeTable;
columns propcheckbox columnrows propcomponents propadditionalProps proptableManager APIHEADER (optional | customizable): search & column visibility management.
TABLE-HEADER: sort, resize & column reorder.
TABLE-BODY: displaying data / loader / no-results, row editing & row selection.
FOOTER (optional | customizable): rows information, rows per page & pagination.
| name | type | description | default value |
|---|---|---|---|
| columns* | array of objects | columns configuration (details) | [ ] |
| rows | array of objects | rows data (details) | [ ] |
| selectedRowsIds | array of ids | the ids of all selected rows (details) | [ ] |
| searchText | string | text for search | "" |
| getIsRowSelectable | function | a callback function that returns whether row selection for the current row should be selectable or disabled | row => true |
| getIsRowEditable | function | a callback function that returns whether row editing for the current row should be allowed or not | row => true |
| editRowId | any | the id of the row that should switch to inline editing mode, (more details about row editing) | null |
| page | number | current page number | 1 |
| pageSize | number | the selected page size | 20 |
| sort | object | sort config. accepts colId for the id of the column that should be sorted, and isAsc to define the sort direction. example: { colId: 'some-column-id', isAsc: true }, to unsort simply pass colId as null |
{ } |
| isLoading | boolean | whether to display the loader | false |
| name | type | description | default value |
|---|---|---|---|
| rowIdField | string | the name of the field in the row's data that should be used as the row identifier - must be unique | 'id' |
| minColumnResizeWidth | number | minimum width for all columns while resizing (doesn't apply to 'checkbox' column) | 70 |
| minSearchChars | number | the minimum characters to type before search will apply | 2 |
| isHeaderSticky | boolean | whether the table header cells will stick to the top when scrolling, or not | true |
| isPaginated | boolean | determine whether the pagination controls sholuld be shown in the footer and if the rows data should split into pages | true |
| enableColumnsReorder | boolean | whether to allow column drag & drop for repositioning | true |
| highlightSearch | boolean | whether to highlight the search term | true |
| showSearch | boolean | whether to show the search component in the header | true |
| showRowsInformation | boolean | whether to show the rows information component (located at the left side of the footer) | true |
| showColumnVisibilityManager | boolean | whether to display the columns visibility management button (located at the top right of the header) | true |
| pageSizes | array of numbers | page size options | [20, 50, 100] |
| isVirtualScroll | boolean | whether to render items in a virtual scroll to enhance performance (useful when you have lots of rows in a page) | true |
| selectAllMode | string | controls the type of "All Selection". Available options are page to select / unselect only the rows in the current page, or all to select / unselect all rows in all pages. If using an async flow, the all option will select all available rows, and the page option combined with batchSize, will select/unselect all available rows in the page |
'page' |
| icons | object of nodes | custom icons config | { sortAscending, sortDescending, clearSelection, columnVisibility, search, loader } |
| texts | object | config for all UI text, useful for translations or to customize the text | { search: 'Search:', totalRows: 'Total rows:', rows: 'Rows:', selected: 'Selected', rowsPerPage: 'Rows per page:', page: 'Page:', of: 'of', prev: 'Prev', next: 'Next', columnVisibility: 'Column visibility' } |
| components | object | This prop gives you the ability to override the internal components with your own custom components (see full list of supported components) | { Default components } |
| additionalProps | object | This prop gives you the ability to pass props to the table's components/modules (see full list of supported additionalProps) | additionalProps={{ header: { ... } }} |
| name | type | description | usage |
|---|---|---|---|
| onColumnsChange | function | triggers when the columns has been changed |
columns => { ... } |
| onSelectedRowsChange | function | triggers when rows selection has been changed | selectedRowsIds => { ... } |
| onPageChange | function | triggers when page is changed | nextPage => { ... } |
| onPageSizeChange | function | triggers when page size is changed | newPageSize => { ... } |
| onSearchTextChange | function | triggers when search text changed | searchText => { ... } |
| onSortChange | function | triggers when sort changed | ({colId, isAsc}) => { ... } |
| onRowClick | function | triggers when a row is clicked | ({ rowIndex, data, column, isEdit, event }, tableManager) => { ... } |
| onEditRowIdChange | function | triggers when rowEditId changed |
rowEditId => { ... } |
| onLoad | function | triggers when tableManager is initialized (details) |
tableManager => { ... } |
| onColumnResizeStart | function | triggers when column resize starts | ({event, target, column}) => { ... } |
| onColumnResize | function | triggers when column resize occur | ({event, target, column}) => { ... } |
| onColumnResizeEnd | function | triggers when column resize ended | ({event, target, column}) => { ... } |
| onColumnReorderStart | function | triggers on column drag. the sort data supplied by react-sortable-hoc using the onSortStart prop |
(sortData, tableManager) => { ... } |
| onColumnReorderEnd | function | triggers on column drop, and only if the column changed its position. the sort data supplied by react-sortable-hoc using the onSortEnd prop |
(sortData, tableManager) => { ... } |
| name | type | description | usage/default value |
|---|---|---|---|
| onRowsRequest | function | triggers when new rows should be fetched | see example |
| onRowsChange | function | triggers when the rows have changed | see example |
| onTotalRowsChange | function | triggers when the total number of rows have changed | see example |
| onRowsReset | function | triggers when the accumulated rows needs to be reset (when searching or sorting) | see example |
| batchSize | number | defines the amount of rows that will be requested by onRowsRequest prop |
the page size of the table |
| requestDebounceTimeout | number | defines the amount of debouncing time for triggering the onRowsRequest prop |
300 |
| totalRows | number | the total number of rows | --- |
Type: array of objects.
This prop defines the columns configuration.
Each column (except for 'checkbox' column) has support for the following properties:
| name | type | description | default value |
|---|---|---|---|
| id* | any | a unique identifier for the column, setting it to 'checkbox' will generate a rows selction column (more details about checkbox column) | --- |
| field | string | the name of the field as in the row data | --- |
| label | string | the label to display in the header cell | the field property |
| pinned | boolean | whether the column will be pinned to the side, supported only in the first and last columns | false |
| visible | boolean | whether to display the column | true |
| className | string | a custom class selector for all column cells | "" |
| width | string | the initial width of the column in grid values (full list of values) | "200px" |
| minResizeWidth | number | the minimum width of the column when resizing | minColumnResizeWidth prop |
| maxResizeWidth | number, null | the maximum width of the column when resizing | null |
| getValue | function | used for getting the cell value (usefull when the cell value is not a string - details) | ({value, column}) => value |
| setValue | function | used for updating the cell value (usefull when the cell value is not a string - details) | ({ value, data, setRow, column }) => { setRow({ ...data, [column.field]: value}) } |
| searchable | boolean | whether to apply search filtering on the column | true |
| editable | boolean | whether to allow editing for the column | true |
| sortable | boolean | whether to allow sort for the column | true |
| resizable | boolean | whether to allow resizing for the column | true |
| search | function | t |
$ claude mcp add react-grid-table \
-- python -m otcore.mcp_server <graph>