The most simple Table implementation in the world, that fits 90% of your use-cases.
- Row Virtualization
- Row selection (Multi & Single)
- Sticky Headers
- Sorting (including multi-sort)
- Column Resizing
- Group Headers
- Pagination
- Infinite scroll
- onRowClick event
- Load more data when reaching bottom
- ⭐️Highly customizable⭐️ with custom css hooks for personal styling
- Double-render. For some reason, row selection has to be a dependency for when calculating columnDefs in order for selected rows which were checked using the checkbox to appear as such in the next render. In the example shown in @tanstack/table it seemed like that isn't necessary. Need to check.
- Table Width. Now that Column-Sizing is a built-in feature, need to figure out the best way to handle table width, and how to make it take up the full size of its container.
install the package:
npm install @talkohavy/table
import and use the Table
component like so:
import { Table } from '@talkohavy/table';
export const data = [
{
id: 1,
first_name: 'Emlen',
last_name: 'Orth',
email: '[email protected]',
gender: 'Female',
ip_address: '163.228.179.208',
},
{
id: 2,
first_name: 'Conrad',
last_name: 'Liepmann',
email: '[email protected]',
gender: 'Male',
ip_address: '225.98.191.215',
},
{
id: 3,
first_name: 'Magnum',
last_name: 'Le Brom',
email: '[email protected]',
gender: 'Male',
ip_address: '170.255.125.199',
},
{
id: 4,
first_name: 'Bette',
last_name: 'Wroughton',
email: '[email protected]',
gender: 'Female',
ip_address: '169.143.132.230',
},
];
export default function App() {
return (
<div style={{ width: '100%' }}>
<Table data={data} />
</div>
);
}
That's it 🙂
Now, since Table is essentially a wrapper around @tanstack/table
, you can pass columnDefs to it as you normally would:
import { Table } from '@talkohavy/table';
import { createColumnHelper } from '@tanstack/react-table';
const columnHelper = createColumnHelper<any>();
const columnDefs = [
columnHelper.accessor('id', { header: 'ID' }),
columnHelper.accessor('first_name', { header: 'First Name', enableSorting: true }),
columnHelper.accessor('last_name', { header: 'Last Name' }),
columnHelper.accessor('email', { header: 'Email' }),
columnHelper.accessor('gender', { header: 'Gender' }),
columnHelper.accessor('ip_address', { header: 'IP Address' }),
];
export const data = [/* ... data here ...*/];
export default function App() {
return (
<div style={{ width: '100%' }}>
<Table data={data} columnDefs={columnDefs} />
</div>
);
}
Play around and have fun exploring 🧡
Here's a list of all supported options:
-
data
type:Array<T>
The only mandatory prop which Table requires.
-
columnDef
type:ColumnDef
Exactly what you know about ColumnDef from
@tanstack/table
. -
showFooter
type:boolean
* Will be explained in the future *
-
rowSelectionMode
type:string
Options: 'none' | 'single' | 'multi'* Will be explained in the future *
-
searchText
type:string
Goes together with
setSearchText
.
The data passed to Table will be filtered by rows that includesearchText
.
* Will be explained in the future * -
setSearchText
type:(value: any) => void
Goes together with
searchText
.* Will be explained in the future *
-
defaultColumn
type:Partial<ColumnDef<TData, unknown>>
* Will be explained in the future *
-
customTableFooter
type:React Component
* Will be explained in the future *
-
initialPageSize
type:number
* Will be explained in the future *