Skip to content

DataViews - filterSortAndPaginate needs entire records to function #70040

Closed

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

Activity

  1. Mayank-Tripathi32 commented on May 2, 2025

    @Mayank-Tripathi32
    Member

    Thank you for reporting this issue.

    After checking the implementation locally, it appears that the function is intended primarily for client-side filtering and pagination—especially in scenarios where the data (such as author records) is already available.

    For reference, the implementation in packages/edit-site/src/components/post-list/index.js demonstrates this usage perfectly.

    That said, I believe we can enhance the function by making the pagination-related arguments optional. When those arguments are provided, we could bypass the built-in logic to offer bit more flexibility. ( will open PR for same)

    Additionally, it might be worth revisiting packages/edit-site/src/components/page-templates/index.js. Relying entirely on client-side filtering for templates can lead to performance issues, particularly when dealing with a large number of templates. I feel we can move the filtering to server-side? I will open an issue for discussion on it.

  2. dannyreaktiv commented on May 2, 2025

    @dannyreaktiv
    Author

    Thanks for looking into it.

    Using DataViews as a replacement for post tables has been very compelling.

  3. t-hamano commented on May 3, 2025

    @t-hamano
    Contributor

    Is the issue reported here essentially the same as #69193?

  4. added
    [Feature] DataViewsWork surrounding upgrading and evolving views in the site editor and beyond
    [Type] BugAn existing feature does not function as intended
    and removed
    [Type] BugAn existing feature does not function as intended
    on May 3, 2025
  5. Mayank-Tripathi32 commented on May 7, 2025

    @Mayank-Tripathi32
    Member

    Is the issue reported here essentially the same as #69193?

    Not quite, Its more about exposing the control of pagination, Its related to actual pagination & sorting logic on client side.

  6. youknowriad commented on Nov 13, 2025

    @youknowriad
    Contributor

    Yes, this function is meant to be used essentially for client side filtering. So I'm going to close as working as intended.

    If your filtering and pagination is done server side, it is your responsibility to transform the "view" object to the right API that is needed by your endpoint. The DataViews is a generic library independent of any backend or endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions