In-memory tables
EuiInMemoryTable is a higher level component wrapper around
EuiBasicTable aimed at automatically handling certain functionality (selection, search, sorting, and pagination) in-memory for you, within certain preset configurations. It takes the full set of data that must include all possible items.EuiMemoryTable relies on referential equality of a column's
name
field when sorting by that column. This particularly applies to JSX nodes.If your JSX name
is not defined outside a component render
cycle or is not correctly memoized with useMemo
, it will break sorting and other in-memory comparisons.
Table selection
To enable selection, both the itemId
and selection
props must be passed. The following example shows how to use EuiInMemoryTable with both controlled and uncontrolled item selection. It also shows how you can display messages, errors and show loading indication.
For uncontrolled usage, where selection changes are determined entirely to be selected initially by passing an array of items to selection.initialSelected
. You can also use selected.onSelectionChange
to track or respond to the items that users select.
To completely control table selection, use selection.selected
instead (which requires passing selected.onSelectionChange
). This can be useful if you want to handle table selections based on user interaction with another part of the UI.
Searching
Search bar
This example shows how to configure EuiInMemoryTable to display a search bar by passing the search
prop. For more detailed information about the syntax and configuration accepted by this prop, see EuiSearchBar.
Search callback
The example shows how to configure EuiInMemoryTable to display a search bar and intercept the search value when it changes so you can perform your own search logic.
External state
The example shows how to configure EuiInMemoryTable when both external and internal search/filter states are in use.
Custom sort values
Sometimes the value displayed in a column is not appropriate to use for sorting, such as pre-formatting values to be human-readable. In these cases it's possible to pass the sortable
prop as a function instead of true
or false
. The function is used to extract or calculate the intended sort value for each item
.
Controlled pagination
By default EuiInMemoryTable
resets its page index when receiving a new EuiInMemoryTable
array. To avoid this behavior the pagination object optionally takes a pageIndex
value to control this yourself. Additionally, pageSize
can also be controlled the same way. Both of these are provided to your app during the onTableChange
callback.
The example below updates the array of users every second, randomly toggling their online status. Pagination state is maintained by the app, preventing it from being reset by the updates.
Props
EuiInMemoryTable
Prop | Description and type | Default value |
---|---|---|
Prop items# | Description and type A list of objects to appear in the table - an item per row T[] | Default value Required |
Prop columns# | Description and type An array of one of the objects: #EuiTableFieldDataColumnType, #EuiTableComputedColumnType or #EuiTableActionsColumnType. EuiBasicTableColumn<T>[] | Default value Required |
Prop className# | Description and type Type: string | Default value |
Prop aria-label# |