Foundation
Main View
Components
Charts
Dialogs
Framer Animations
Forms
Grids
Typography
Tools
Package: @uireact/table
Used to render information in a table that is filterable and sortable.
1. Make sure you install peer dependencies first:
2. Install package:
npm i -S @uireact/table
npm i @uireact/foundation @uireact/table
The table will render the data as you pass it in the data prop, no sort / filter will be applied till the user interacts with those elements.
<UiTable bordered data={{ headings: [{ label: 'No.' }, { label: 'Summary', sort: false } , { label: 'Price' }], items: [ { id: '1', cols: [1, 'item 1', '$10'] }, { id: '2', cols: [2, 'item 2', '$20'] }, { id: '3', cols: [3, 'item 3', '$30'] }, { id: '4', cols: [4, 'item 4', '$40'] }, { id: '5', cols: [5, 'item 5', '$50'] }, { id: '6', cols: [6, 'item 6', '$60'] }, { id: '7', cols: [7, 'item 7', '$70'] }, { id: '8', cols: [8, 'item 8', '$80'] }, { id: '9', cols: [9, 'item 9', '$90'] }, { id: '10', cols: [10, 'item 10', '$100'] }, ], }} selected="3" onClick={(id) => { selected = id; console.log(`id ${id} selected`); }} />
onClick
prop is present then it will be executedselected
id to the table that row will show as selected in the tableIn the previous example we are using the prop bordered
to display borders although is not enable by default given that tables are hard to stylized for multiple use cases. So, to stylized the table we recommend passing
a className
value, this will be attached to the Table
element and you can style the table from there.
<UiTable data={{ headings: [{ label: 'Summary'}, { label: 'Price'}], items: [{ id: '1', cols: ['item 1', '$10'] }], }} category="tertiary" />
<UiTable data={{ headings: [{ label: 'Summary'}, { label: 'Price'}], items: [{ id: '1', cols: ['item 1', '$10'] }], }} category="tertiary" filterBoxPosition="right" />
<UiTable data={{ headings: [{ label: 'Summary'}, { label: 'Price'}], items: [{ id: '1', cols: ['item 1', '$10'] }], }} withFilter={false} withSort={false} />
<UiTable data={{ headings: [{ label: 'Summary', sort: false}, { label: 'Price'}], items: [{ id: '1', cols: ['item 1', '$10'] }], }} withFilter={false} withSort={false} />
This is useful when you want to render a component in each of the elements.
<UiTable data={{ headings: [{ label: 'Summary'}, { label: 'Price'}, { label: 'Actions', sort: false }], items: [ { id: '1', cols: ['item 1', '$10', <UiIcon icon="Edit" />] }, { id: '2', cols: ['item 2', '$20', <UiIcon icon="Edit" />] }, ] }} />