npm i reatable
import { Table, TableContent, Pagination, Loader, usePagination, useSort, useFilter } from "reatable"
it is the basic example for reatable.
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
Drew | Kai | 24 | male |
Frankie | Riley | 70 | male |
Brook | Mason | 38 | female |
West | Emery | 31 | male |
West | Bailey | 49 | female |
Table or TableContent setting className attribute will remove the default stylesheet in table to prevent conflict to the setted class.
Table property data must be an array of object that contains id or key to distinguish it from each other to prevent bugs.
you can mutate the appearance and elements of table cell
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
Drew | Kai | 24 | male |
Frankie | Riley | 70 | male |
Brook | Mason | 38 | female |
West | Emery | 31 | male |
West | Bailey | 49 | female |
you can group your table column headers.
SyntaxError: Unexpected token (31:78) 27 : columns: [ 28 : { 29 : dataIndex: "gender", 30 : label: "Male", 31 : render: (gender) => gender === "male" && "<span role="img">✔️</span>" ^
you can group column headers as many group as you like.
Table property data must be an array of object that contains id or key to distinguish it from each other to prevent bugs.
whenever the data is too big you need to paginate which is built-in in reatable.
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
Eli | Corey | 34 | male |
August | Shawn | 59 | male |
Shawn | River | 88 | male |
Rowan | Maxwell | 43 | female |
Pat | Lake | 100 | male |
pagination will only be applicable if you assign value in pagination property pageSize.
it has built-in feature column sorting.
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
Val | Clay | 93 | female |
Shawn | River | 88 | male |
Rudy | Avery | 73 | female |
Rowan | Maxwell | 43 | female |
Reed | Gabriel | 37 | male |
the column property sortable can be assign boolean that will be sorted by the built-in sorting algorithm of the component. or you can make your own algorithm by assigning function that compares the two argument.
built-in sorting algorithm is not applicable in asynchronous table.
you can make a collapsible table.
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
Drew | Kai | 24 | male |
West | Emery | 31 | male |
Brook | Mason | 38 | female |
West | Bailey | 49 | female |
Frankie | Riley | 70 | male |
you can make a collapsible table using button in columns render.
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
Drew | Kai | 24 | male |
West | Emery | 31 | male |
Brook | Mason | 38 | female |
West | Bailey | 49 | female |
Frankie | Riley | 70 | male |
it has built-in feature column filtering.
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
Eli | Corey | 34 | male |
August | Shawn | 59 | male |
Shawn | River | 88 | male |
Rowan | Maxwell | 43 | female |
Pat | Lake | 100 | male |
built-in filtering algorithm is not applicable in asynchronous table.
you can make asynchronous table.
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
Jesse | Jules | 73 | female |
Tyler | Aiden | 74 | female |
Ash | Remy | 22 | male |
Winter | Andy | 32 | female |
Daryl | Campbell | 37 | male |
every action you made the loader will be shown because the table is asynchronous which makes it to wait for the sever response.
you can customize your table appearance.
all the component and hooks are only applicable inside Table component.
passing the className in Table will be unnecessary, since you can access directly to the TableContent to assign className.
you can customize your loader appearance.
Loader will only be visible when the table is asynchronous.
you can customize pagination container and list and still using the Pagination components algorithm.
if you don't like the overall Pagination component model, then you can create your own by using usePagination.
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
Jesse | Jules | 73 | female |
Tyler | Aiden | 74 | female |
Ash | Remy | 22 | male |
Winter | Andy | 32 | female |
Daryl | Campbell | 37 | male |
Elliott | Roan | 77 | female |
Emerson | Kelsey | 76 | male |
Sam | Kelly | 52 | male |
Tatum | Landry | 16 | male |
Amari | Jayden | 82 | female |
there is no built-in component for page size changer but you can make your own by adding a few lines of code.
you can do all you want on filtering by using hook useFilter, this is just one of many things that you can do.
filter by search is so typical in dynamic table. this is just the idea to create greater things.
you can customize and create your own features on the table row(tr) and cell(td) in your own perspective, design and functionalities by using useColumn hooks, you can get your column settings you entered in the Table property columns. the customize cell example is editable and it is just one of many features you can create.
you can use hooks especially useColumn to get the settings on columns and create your very own features.
if you don't like the given empty data design you can make your own.
First Name First Name | Last Name Last Name | Age Age | Gender Gender |
---|---|---|---|
you can use the given hooks in this customizes components.
it is just a mediocre example on how you create a column header with sortable. it is just an idea for you to create greater header.
you can use the given hooks in this customizes components.
it is an idea on how to pass a data on modal, since modal is commonly use to handle changes in table.
First Name First Name | Last Name Last Name | Age Age | Gender Gender | Action Action |
---|---|---|---|---|
Jesse | Jules | 73 | female | |
Tyler | Aiden | 74 | female | |
Ash | Remy | 22 | male | |
Winter | Andy | 32 | female | |
Daryl | Campbell | 37 | male |
it is an example to apply a selection on your table with sending multple data in modal.
First Name First Name | Age Age | Gender Gender | |
---|---|---|---|
Jesse | 73 | female | |
Tyler | 74 | female | |
Ash | 22 | male | |
Winter | 32 | female | |
Daryl | 37 | male |
API
It is the table wrapper.
Property Property | Type Type | Default Default | Description Description |
---|---|---|---|
columns | object[] | - | The settings of the table columns. |
data | object[] | - | The data of the table which is to be display. |
className | string | - | The className of your table. |
pagination | object | - | The setting of your pagination. |
collapsible | object | - | The setting of your expandable row. |
asynchronous | boolean | false | To determine if the table data will be requested when action is pagination, sort, and filters. Plus, The loader will be activated while waiting on the request. |
onChange | React.useCallback | - | It will be triggered when there is a action changes in the table like pagination, sort, and filters. |
It is the table itself.
Property Property | Type Type | Default Default | Description Description |
---|---|---|---|
as | object | - | It is use to customize certain components without changing the main algorithm. |
className | string | - | The className of your table. |
It is the pagination.
Property Property | Type Type | Default Default | Description Description |
---|---|---|---|
as | object | - | It is use to customize certain components without changing the main algorithm. |
className | string | rt-pagination | The className of your pagination. |
nextLabel | string | element | 'next' | The label of the next button. |
prevLabel | string | element | 'prev' | The label of the prev button. |
It is the loader when the table is asynchronous.
Property Property | Type Type | Default Default | Description Description |
---|---|---|---|
children | element | <div className="rt-loader"/> | Your customize element loader. |
Hooks
It is use to create your own component pagination.
Property Property | Type Type | Default Default | Description Description |
---|---|---|---|
const { | |||
allowPagination, | boolean | - | It use to determine if pagination will be display. |
totalPages, | boolean | - | It is the total pages of the pagination. |
page, | number | - | It is the number of the current page. |
setPage, | function | - | It is use to assign the current page in the table state. |
} = usePagination() |
It is use to create your own component sort. it is useful in Table property as Column.
Property Property | Type Type | Default Default | Description Description |
---|---|---|---|
const { | |||
sortable, | boolean | - | It is use to determine if column is sortable. |
sortOrder, | 'asc' | 'desc' | null | - | It is the state order currently the column is in. |
handleSort, | function | - | It is the sort handler that suppose to be assign in the certain element property onClick |
} = useSort( | |||
dataIndex | string | - | To get the column setting. |
) |
It is use to create your own component filteration.
Property Property | Type Type | Default Default | Description Description |
---|---|---|---|
const { | |||
filterable, | boolean | - | It is use to determine if column is filterable. |
filters, | object[] | - | It is the content you put in Table property columns |
filterSearch, | object | - | It is the content you put in Table property columns |
filterMultiple, | boolean | - | It is the content you put in Table property columns |
filterState, | object[ ] | - | It is the current state of the filters which had been applied. |
setFilter, | function | - | It is use to assign filters in the table state. |
} = useFilter( | |||
dataIndex | string | - | To get the column setting. |
) |
It is use to get the column settings in Table property columns.
Property Property | Type Type | Default Default | Description Description |
---|---|---|---|
const | |||
column | object | - | It is the setting of the column. |
= useColumn( | |||
dataIndex | string | - | To determine which column setting you are getting. |
) |