kibana/packages/shared-ux/table_persist
Luke Elmers b6287708f6
Adds AGPL 3.0 license (#192025)
Updates files outside of x-pack to be triple-licensed under Elastic
License 2.0, AGPL 3.0, or SSPL 1.0.
2024-09-06 19:02:41 -06:00
..
src Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
index.ts Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
jest.config.js Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
kibana.jsonc
package.json Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
README.md
tsconfig.json

@kbn/shared-ux-table-persist

This package contains the useEuiTablePersist hook that can be used in components containing Eui tables for storing their page size ("rows per page" value) or the current sort criteria in local storage so that the user's preferences for these properties can persist.

The package also exports some table-related constants (e.g. DEFAULT_PAGE_SIZE_OPTIONS) for use across tables in Kibana Stack Management for consistency.

Usage:

interface Props {
  items: T[];
}

const MyTableComponent: FunctionComponent<Props> = ({ items }) => {
  const columns = [
    {
      field: 'name',
      name: 'Name',
      sortable: true,
    },
    ...
  ];

  const { pageSize, sorting, onTableChange } = useEuiTablePersist<T>({
    tableId: 'myTableId',
    initialPageSize: 50,
    initialSort: {
      field: 'name',
      direction: 'asc',
    },
  });

  const pagination = {
    pageSize,
    pageSizeOptions: DEFAULT_PAGE_SIZE_OPTIONS,
  };

  return (
    <EuiInMemoryTable
      items={items}
      columns={columns}
      pagination={pagination}
      sorting={sorting}
    />
  );
};