Table allows the rendering of static and dynamic content for data-oriented and data-agnostic tables to prevent the developer from having to transform their data to be able to render in a table. Composition is the central point, as is the use of the render props pattern to allow this so that the component can offer OOTB features, such as sorting and nested row.
Unlike static content, dynamic content is when the options can change during the lifecycle of the application or when the data comes from a service. Dynamic content rendering is data agnostic, this allows you to configure how to render the component options regardless of the chosen data structure. For more information about controlled and uncontrolled components, visit this blog post.
Warning
When implementing ClayTable from a React application, the icons may not render.
The
Application Provider
method will make the icons available for use.
Column sorting is implemented OOTB so the developer doesn’t need to worry about implementing the UI details but the developer still needs to add their filter layer since the component is data-agnostic and allows you to do this asynchronously, it is important, especially when your data is paged, that the filter must happen in the backend.
It is also possible to implement your own logic on the client side when your data is predictable, check out the pseudocode.
Info
Column sorting is only enabled for columns that contain the
sortable
API defined.
Most tables with sorting can have a lot of data and are paged so the sorting must happen on the server side instead of implementing the logic on the client side. You can achieve this level of implementation by composing using the useResource hook.
Implementing nested row allows you to render a table as a tree view. It is not necessary that you have to change your composition to render in tree view but just configure the nestedKey property to inform which nested key and the composition can continue in the same way.
When using the nested row pattern, Clay automatically changes the accessibility behavior to use the treegrid recommendation instead of the default behavior.
Limitation
The unique id of a row does not work properly when configured via
key
in the Row component property to
deal with the nodes expandability, it is necessary that the
id
key is defined in your row data to use as unique id.
Expanding nodes is done OOTB in the component but it is also possible to control the state to modify behaviors if necessary or use it to save a session to improve the user experience.
Warning
If your data structure does not have a key property
id
that is used as a unique identifier for each item, you need to configure
which key will be used to identify the item by using the
itemIdKey
API in the Table component.
When the tree is very large with a lot of data on a single node, loading the data asynchronously is essential to reduce the initial data payload and memory space. Table supports asynchronous node loading when the user expands a node.
When returning
void
,
null
or
undefined
the Table will do nothing.
When returning the
items
will add to the tree.
Warning
If you have an error in the asynchronous call of the
onLoadMore
method, only the suppression is done and an error is thrown on the console.
When adding a new asynchronous item to the tree, the onItemsChange method is respectively called to update the tree with a new value if the items prop is controlled.
When a tree is very large, loading items (nodes) asynchronously is preferred to
decrease the initial payload and memory space. The callback is called every time
the item is a leaf node of the tree.
onSortChange
((sorting:Sorting|null) =>void) |undefined
Callback for when the sorting change (controlled).
Sometimes we are unable to remove specific table columns from the DOM
and need to hide it using CSS. This property can be added to the “new”
first or last cell to maintain table styles on the left and right side.
expanded
boolean|undefined
Fills out the remaining space inside a Cell.
sortable
boolean|undefined
Whether the column allows sortable. Only available in the header column.
textAlign
"center"|"end"|"start"|undefined
Aligns horizontally contents inside the Cell.
truncate
boolean|undefined
Truncates the text inside a Cell.
wrap
boolean|undefined
width
string|undefined
Sets the column width.
textValue
string|undefined
Sets a text value if the component’s content is not plain text.