You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DataViews - filterSortAndPaginate needs entire records to function #70040
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.
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.
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.
Activity
Mayank-Tripathi32 commentedon May 2, 2025
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.jsdemonstrates 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.dannyreaktiv commentedon May 2, 2025
Thanks for looking into it.
Using
DataViewsas a replacement for post tables has been very compelling.t-hamano commentedon May 3, 2025
Is the issue reported here essentially the same as #69193?
Mayank-Tripathi32 commentedon May 7, 2025
Not quite, Its more about exposing the control of pagination, Its related to actual pagination & sorting logic on client side.
youknowriad commentedon Nov 13, 2025
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.