Controlled object-table
A controlled object-table
(<
automatic
="false">
) contains data that is controlled by external code only. It will therefore not handle the pagination, sorting or filtering of data. Instead, you are required to communicate to the component:
the amount of pages,
what data should display for the current page,
and what should happen when the state changes.
When to use a controlled object-table
object-table
The table represents remote API data
When working with Big data
Running into performance issues
Implementation
The Showcase: Object Tables template app contains an example implementation of a controlled object-table
. Check it out!
Implementing a controlled object-table
requires the use of on-state-change
, mode
="paginate"
, automatic
="false"
and the page-count
attributes on the object-table
.
When a table receives an automatic="false"
attribute it will automatically go into controlled mode. The page-count
attribute must contain a function which returns the total number of pages, since the component cannot determine the page count in its own.
An on-state-change
attribute also needs to be added to record the next state of the object-table
for when a page button is selected or filtering gets applied. When this function fires, you should mutate the query passed to the table to represent the new state by means of limiting, sorting and skipping the underlying query.
Here is the full list of steps:
Create a variable to store the initial state and the computed pages
Use this variable to setup the initial query
Setup a function for when the state changes
Set the
object-table
up similar to this example:
Last updated