Skip to content

fix(bindx-dataview): compute real total count for top-level DataGrid (#44)#45

Merged
vparys merged 1 commit into
mainfrom
fix/datagrid-total-count-not-computed
Jun 17, 2026
Merged

fix(bindx-dataview): compute real total count for top-level DataGrid (#44)#45
vparys merged 1 commit into
mainfrom
fix/datagrid-total-count-not-computed

Conversation

@vparys

@vparys vparys commented Jun 17, 2026

Copy link
Copy Markdown
Member

Fixes #44.

Problem

Top-level <DataGrid> never computed a real total count. It only set the count lazily, when the current page returned fewer rows than the page size (itemCount < queryLimit) — i.e. only on a partial last page. On any list spanning more than one full page, paging.info.totalCount / totalPages stayed null, so the UI could not show a row count or "page X of Y", and "jump to last page" was permanently disabled (paging.last() early-returns on totalPages === null). When the total was an exact multiple of the page size, the count was never learned even by paging to the end.

Approach

Mirrors how Contember's own react-dataview solves it (useDataViewTotalCount): issue a standalone COUNT query keyed only on the filter — not on limit/offset — so paging through the list does not recompute it, and refresh() can force a recount.

  • Adapter layer — new count query type (CountQuery / CountQueryResult).
    • MockAdapter: counts the filtered set before pagination.
    • ContemberAdapter: paginate<Entity> { pageInfo { totalCount } }, batched into the same request as the sibling list query.
  • useEntityCount(entity, { filter, refreshToken }) — new reusable hook in @contember/bindx-react that enqueues the count through the existing batcher.
  • WiringDataGrid, useDataView and SelectDataView now feed the count into paging.setTotalCount(...). The original partial-page heuristic is kept as a fallback until the count resolves (and for adapters that don't implement count queries).
  • refreshTotalCount() now drives a recount via a paging refresh token (PagingStateResult.totalCountRefreshToken) instead of merely nulling the displayed total.

Tests

  • tests/react/dataview/dataGridPaginationTotalCount.test.tsx — the issue's reproduction (multi-page list exposes totalCount / totalPages; last-page jump enabled), now passing.
  • tests/react/dataview/dataGridCountQuery.test.tsx — total reflects the active filter; last-page jump lands on the right rows; count is keyed on the filter, so paging does not re-issue it (verified with a spy adapter).
  • tests/unit/adapter/countQuery.test.tsMockAdapter count query (no filter / filtered / unknown entity / independent of limit/offset).

All new tests pass; bun run build and bun run typecheck are clean. The 10 pre-existing failures on main (browser/playground "(unnamed)" cases + one form dirty-tracking test) are unrelated and unchanged by this PR.

Top-level <DataGrid> only set the total count lazily, when the current
page returned fewer rows than the page size (`itemCount < queryLimit`) —
i.e. only on a partial last page. On any list spanning more than one full
page, `paging.info.totalCount` / `totalPages` stayed `null`, so the UI
could not show a row count or "page X of Y", and "jump to last page" was
permanently disabled.

Mirror how Contember's react-dataview does it: issue a standalone COUNT
query keyed only on the filter (not on limit/offset), so paging does not
recompute it. Adds a `count` query to the adapter layer (Mock +
Contember, via `paginate<Entity> { pageInfo { totalCount } }`) and a
`useEntityCount` hook, wired into DataGrid, useDataView and SelectDataView.
The partial-page heuristic is kept as a fallback until the count resolves.

`refreshTotalCount()` now drives a recount via a paging refresh token
instead of just nulling the displayed total.

Fixes #44
@vparys vparys merged commit a4c1bba into main Jun 17, 2026
3 checks passed
@vparys vparys deleted the fix/datagrid-total-count-not-computed branch June 17, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Top-level DataGrid never computes total count on multi-page lists (no COUNT query)

1 participant