Skip to content

DataViews - filterSortAndPaginate needs entire records to function #70040

@dannyreaktiv

Description

@dannyreaktiv

Description

https://github.com/WordPress/gutenberg/blob/72c922b679cbc0d83220514165ea66837de131ca/packages/dataviews/src/filter-and-sort-data-view.ts#L148C1-L156C3

If one is using the filterSortAndPaginate() function, then it requires the queryArgs for the records to be per_page=-1 for totalItems and totalPages to be non-null. If the number of records is large (1,000+), then it can take a long time for all the records to be returning from the host.

However, if the queryArgs is per_page=view.perPage (as it is in some of the documentation), then filterSortAndPaginate() does not work because the filteredData.length is just the number of records for a single page.

Removing the lines related to returning the totalItems and totalPages, and using the totalItems and totalPages from useEntityRecords(), lets the DataView and records function as expected.

Step-by-step reproduction instructions

When using DataViews, set the queryArgs to per_page=view.perPage, and try to use it with filterSortAndPaginate().

totalItems and totalPages will be empty.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] DataViewsWork surrounding upgrading and evolving views in the site editor and beyond[Type] BugAn existing feature does not function as intended

    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