Select All Matching Rows
A selection normally lists row keys, so it can only hold rows the table has loaded. "Select all N matching" (the Gmail pattern) selects every row that matches the current filter and search — 40 000 of them if need be — and runs a bulk action on that set server-side, without loading a single extra row. Since 0.1.147.
<AsTableRoot url="/api/db/tables/tasks" select-all-matching>
<AsTableActions />
<AsTable select="multi" />
</AsTableRoot>Tick the header checkbox: once every loaded row is selected the table shows a banner — All 25 rows on this page are selected. Select all 1 204 matching. Clicking it switches to a query selection; the toolbar then runs the actions that accept one on all 1 204 rows.
What it needs
The banner is offered only when all of these hold (state.canSelectAllMatching):
| Requirement | Why |
|---|---|
<AsTableRoot select-all-matching> | Opt-in, default off — existing tables see no change. |
select="multi" on the renderer | Single-select and no-select tables never hold a query selection. |
A server-backed table (url, no queryFn) | The server resolves the matching rows; a custom fetcher cannot. |
| More matching rows than loaded ones | Otherwise "select all on the page" already is "all matching". |
A 'rows' action that takes a query target | Something must be able to act on the set (see below). |
An action takes a query target when the server opts it in — queryTarget on the @DbAction in moost-db, which /meta reports as queryTarget: { maxRows }. See the atscript-db query targets guide for the server side.
The query selection
While a query selection is held:
state.querySelectionholds{ query, signature, excluded, total }—queryis the filter (force filters and custom filter conditions included),$searchterm and search index the table was showing; sorting, columns and paging are not part of it.state.selectedRowsis empty. Ticking a row off adds its key toexcluded; ticking it back removes it. Every row not excluded reads as selected (state.isPkSelected), loaded or not.state.selectedCountistotal − excluded.length. Code that compared it withselectedRows.lengthshould readstate.selectioninstead — one value for both modes:{ mode: "ids", ids, count }or{ mode: "query", query, excluded, total, count }.- The header checkbox reads checked while no loaded eligible row is excluded, indeterminate otherwise — never unchecked. Clicking a checked header ends the query selection; clicking an indeterminate one re-selects the excluded loaded rows.
- The banner reads All 1 204 matching rows are selected. Clear selection.
state.clearSelection()ends it from code.
Bind it with v-model:query-selection on <AsTableRoot> to keep it outside the table (null while the selection is selectedRows).
When it is dropped
| Change | Query selection |
|---|---|
| Filter, search term or search index | Dropped; @selection-reset { reason: "scope" } |
| Sorting, columns, paging, scrolling, relevance toggle | Kept |
| A refetch of the same query (refresh, live refresh) | Kept; total follows the new count |
| A query-targeted action succeeded | Cleared — the rows it touched have changed |
selectedRows written from outside (v-model) | Dropped (the explicit selection wins) |
Renderer switched off select="multi", prop turned off | Cleared |
selectionPersistence does not apply to a query selection — it has no keys to trim.
Running actions on it
In a query selection <AsTableActions> resolves to the 'rows' level with no ids:
- an action with
queryTargetwhosemaxRowscovers the count is enabled; - one with a smaller
maxRowsis shown disabled — At most 500 rows; - every other
'rows'action is shown disabled — Not available for all matching rows — select rows individually.
The loaded rows' $actions are not consulted: a page of rows cannot speak for the rest. The server checks every row when the action runs and reports the rows it skipped.
Clicking an enabled action:
- counts the rows (
client.countActionTarget— a dry run; the handler does not run). A refusal such asTARGET_TOO_LARGEsettles as the action's error result. - confirms with that count — the action's
promptTextwith$N= the count, or Run “Archive” on 1 203 rows? when it has none; an action with an input form opens its dialog titled Set priority · 1 203 rows. - runs it (
client.actionOnQuery) withexpectCount= the confirmed count. If the set changed in between (409TARGET_CHANGED) the user is asked once more with the new count.
The @action emit carries ids: [] and a result with target: { matched, summary? } — summary is the server's TDbActionTargetSummary (processed, skipped with reasons, failed) when the handler returned one:
function onAction(action: TVueTableActionInfo, ids: unknown[], result: ActionResult) {
if (result.ok && result.kind === "backend" && result.target?.summary) {
const { processed, skipped, matched } = result.target.summary;
toast(`${action.label}: ${processed} of ${matched} rows, ${skipped.length} skipped`);
}
}To run one from code, pass the target to invoke yourself: state.actions.invoke(action, undefined, { target, expectCount }), with state.actions.countTarget(action, target) for the count.
Banner and slots
<AsTable> and <AsWindowTable> render the banner above the rows inside a polite live region, so both switches are announced; its buttons are plain buttons, and focus moves to the new one when they swap. Replace its content with #selection-banner:
<AsTable select="multi">
<template #selection-banner="{ selection, selectAllMatching, clearSelection, loadedCount }">
<template v-if="selection.mode === 'query'">
{{ selection.count }} selected · <button @click="clearSelection">Clear</button>
</template>
<template v-else>
{{ loadedCount }} selected · <button @click="selectAllMatching">Select all</button>
</template>
</template>
</AsTable>#header-__select also receives mode ("ids" / "query"), canSelectAllMatching and selectAllMatching, and #cell-__select's selected reflects the query selection. <AsTableRoot>'s default slot exposes selection, canSelectAllMatching, selectAllMatching and clearSelection.
<AsWindowTable> offers the banner while the dataset is only partly loaded — that is the point — and reads "All N rows loaded are selected". For that, a window table that can offer it shows the header checkbox while partly loaded too, acting on the cached rows (normally it appears only once every row is loaded — see What the header checkbox acts on); tables without the opt-in keep the old rule.
Exclusions are remembered by row identity (preferredId, plus any delegated idMap columns), not by object reference, so a row unticked before a refetch stays unticked after it — with the default rowValueFn too.
DOs and DON'Ts
- Do opt the server action in with
queryTargetand keep the action's owndisabledpredicate — the server skips rows it rejects and reports them. Don't expect:row-selectableto keep unloaded rows out: it can only gate loaded rows; in a query selection the server gate decides. - Do read
state.selection(orselectedCount) for counts. Don't readselectedRows.length— it is0in a query selection. - Do show
result.target.summaryafter a run — skipped rows (disabled, out of scope, changed since the count) are reported, never silently dropped. - Don't expect a custom
queryFntable to offer the banner — only the server can resolve "every matching row".
See also
- Actions & Selection — action levels, the toolbar, the explicit selection.
- Row actions on a view — delegated actions also accept query targets.
@atscript/vue-tableAPI —QuerySelection,TableSelection,ActionQueryTarget.