Table

Display tabular data in format.

General

Display formatted data in rows and columns.

compose

Show other components in the table.

width

Specifies the width of all or part of the columns.

actions

Custom elements can be displayed in the table, and any changes will be immediately rendered.

update row

You can use custom elements to update a specific row.

custom head

TypeScript Example

Get a better experience in TS by specifying a generic type.

type User = {
  name: string
  role: string
  records: Array<{ date: string }>
}
const renderHandler: TableColumnRender<User> = (value, rowData, index) => {
  return <div>{rowData.date}</div>
}
const data: Array<User> = [
  { name: 'witt', role: 'admin', records: [{ date: '2021-05-01' }] },
]

const MyComponent = () => (
  <Table<User> data={data}>
    <Table.Column<User> prop="name" label="username" />
    <Table.Column<User> prop="role" label="role" />
    <Table.Column<User> prop="records" label="records" render={renderHandler} />
  </Table>
)

APIs

Table.Props

AttributeDescriptionTypeAccepted valuesDefault
datadata sourceArray<T>--
initialDatainitial dataArray<T>-[]
emptyTextdisplayed text when table's content is emptystring--
hovertable's hover effectboolean-true
onRowcallback row's content by clickTableOnRowClick--
onCellcallback cell's content by clickTableOnCellClick--
onChangedata change event(data: T) => void--
rowClassNameset className to each rowTableRowClassNameHandler--
...native propsTableHTMLAttributes'id', 'name' ...-

Table.Column.Props

AttributeDescriptionTypeAccepted valuesDefault
prop(required)table-column's propstring--
labeltable-column's labelstring--
widthwidth number (px)number--
classNameset className to each columnstring--
renderrender returns elements in all columnsTableColumnRender--

TableOnRowClick

type TableOnRowClick<T> = (rowData: T, rowIndex: number) => void

TableOnCellClick

type TableOnCellClick<T> = (
  value: T[keyof T],
  rowIndex: number,
  columnIndex: number,
) => void

TableRowClassNameHandler

type TableRowClassNameHandler<T> = (rowData: T, rowIndex: number) => string

TableColumnRender

type TableColumnRender<T extends Record> = (
  value: T[keyof T],
  rowData: T,
  rowIndex: number,
) => JSX.Element | void