Skip to content

[EuiInMemoryTable] Pagination breaks when search.onChange is configured #3445

@cjcenizal

Description

@cjcenizal

To reproduce this problem, configure an EuiInMemoryTable with something like this:

const search = {
  onChange: (data) => this.setState(queryText: data.query.text),
  box: {
    incremental: true,
  },
};

// The items fed to the table will typically use the query text as a filter.
// This is a React best practice.
const filteredItems = this.state.items.filter(item => item.name.includes(this.state.queryText));

The bug arises due to the new array being generated each render by the filtering logic. EuiInMemoryTable deliberately treats a new array as a trigger for resetting pagination to the first page. This manifests as nonresponsive pagination whenever search.onChange is configured.

After discussing this with @chandlerprall we concluded that a reasonable solution would be to document best practices on the example page, which is to cache the filtered rows on state instead of calculating them inside of the render method. Documentation would include things like:

  • Updating an example to configure search.onChange and demonstrate this best practice.
  • Adding a comment to the example code pointing out the reason for caching the filtered result on state.
  • Adding a callout to describe this best practice and reason for it, since it contradicts conventional React best practices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationIssues or PRs that only affect documentation - will not need changelog entriesstale-issue(Don't delete - used for automation)stale-issue-closed(Don't delete - used for automation)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions