Table
Public API
data
Every object in this array will potentially be rendered as a table row. The shape of the data is up to you, the only requirement is that every object (AKA row) must have an attribute that uniquely identifies the object in the array.
We call this attribute
uniqueIdAttribute
, which you will be able to specify later on.
An example data shape:
actions
At the moment, we have only two types of action modules:
- button, for simple actions like deleting a row, navigating to another page, etc.
- edit, to be used if you want to allow the data to be editable.
Think of actions as verbs one would want to apply to each of the Table rows, like a button View to navigate to another page with detailed information about the row. Another example would be a button Delete to delete a row. Actions will be appended to each row.
When you define an action, you are telling Table how you want to be notified when your the button is clicked. Table will let you know via the onAction
event every time a button is clicked.
Table does not provide the logic to handle actions, the implementation for deleting a row, navigating to another page, etc. it's up to you.
The shape of actions
is as follows:
actionButtonMenuIndex
Tables can become bloated if you use lots of actions, in order to prevent this, overflowing actions are wrapped by an ActionsMenu, a contextual menu accessible via the meat ball button of each row.
You can specify which actions are sent to the ActionsMenu using the actionButtonMenuIndex
prop, a number that acts like a partition index that will take your actions array and slice it. The actions whose index is greater or equal to actionButtonMenuIndex
will be part of ActionsMenu, the rest will be displayed as usual.
This only applies to button actions, edit action will always be displayed as usual.
resolveRecordActions
By default, all actions are added to All rows, this might not be what you want: Under certain scenarios, some actions might not be available or allowed depending on certain (business-logic) conditions. resolveRecordActions
is a function you can pass to derive if a certain action can be displayed for each row.
signature
example
The following example assumes two actions have been defined: edit and view:
- edit action will only be added if the row (record) has its deflected property set to false
- view action will only be added if the row (record) is a FAQ
This is a powerful way of conditionally rendering actions for each row.
dataDisplay
Here you can describe each of the visible columns in your table. dataDisplay items have a special shape too, good news is that you have plenty more options to choose from. Please choose the one that best fits your data type.
supported data types (modules)
onAction (event handler)
A function you can pass to handle every event your table emits. Every event carries two pieces of information:
- action, the object (button) that was actually clicked and
- record, the object that represents the row upon which the action was applied.
tip: do not bloat your table! keep the number of buttons low, specially if you are targetting mobile devices.
uniqueIdAttribute
Specifies the attribute that uniquely identifies every object in the data array.
It is always recommended to speficy
uniqueIdAttribute
. Although it can be derived from the data itself, the inference function defines the following as possible values:
- eid
- uuid
- id
- sys_date_created
- number
If you see a warning like 'Each child in a list should have a unique "key" prop' from Table, please make sure you pass this prop to prevent Table's auto-id-inference from kicking-in and possibly infering undefined if the data you pass does not have any of the possible values.
Mixing everyting together
With the four props described earlier, we can easily create a table: (open your dev tools!)
Empty Table
In this example, Table does not render anything, since there is no data. This can also happen if no columns are defined. If either Data nor Colums are defined, it is assumed that we do not want to display a Table at the moment: