Repository navigation
Replies: 1 comment
|
+1 — we hit the same wall with server-paginated tables. For bulk actions, include/exclude is the only shape that scales. A few edge cases worth settling in the design:
Until something lands, this works in userland today (with type Sel = { mode: 'include' | 'exclude'; ids: Set<string> }
const [sel, setSel] = useState<Sel>({ mode: 'include', ids: new Set() })
const rowSelection = useMemo(
() => Object.fromEntries(
data.map(r => [r.id, sel.mode === 'exclude' ? !sel.ids.has(r.id) : sel.ids.has(r.id)]),
),
[data, sel],
)
const toggleRow = (id: string) =>
setSel(s => {
const ids = new Set(s.ids)
ids.has(id) ? ids.delete(id) : ids.add(id)
return { ...s, ids }
})
const selectAll = () => setSel({ mode: 'exclude', ids: new Set() })
const clearAll = () => setSel({ mode: 'include', ids: new Set() })
const selectedCount = sel.mode === 'exclude' ? rowCount - sel.ids.size : sel.ids.size
// bulk action payload: { mode: sel.mode, ids: [...sel.ids], filters }Rows loaded later pick up the right state automatically, because |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
We have a remote table with server-side pagination. The server has 100,000 rows, and we load one page at a time.
We want "select all" to select all 100,000 rows. Today, the table selects only the loaded rows:
toggleAllRowsSelected(true)reads the IDs fromgetPreGroupedRowModel().flatRows. These are only the loaded rows.getIsAllRowsSelected()checks onlygetFilteredRowModel().flatRows. When all loaded rows are selected, the header checkbox shows "all selected". But the server has more rows.rowSelectionhas 1,000,000 keys. We cannot send all these IDs to the server for a bulk action.A fix in
getIsAllRowsSelected()alone does not help. If it compares withrowCount, the header checkbox never shows "all selected" after a click.Idea: an opt-in "exclude" selection mode. MUI X v8 has this as
{ type: 'include' | 'exclude', ids }(docs). The AG Grid server-side row model hasselectAllandtoggledNodes(docs).row.toggleSelected(false)adds the row ID to the set, androw.toggleSelected(true)removes it.rowCountminus the number of exceptions.manualRowSelection: true, only allows this behavior.The default
RowSelectionStateshape does not change. A table without the opt-in works as before.Related: #3513, #5929, #6039, #4781
All reactions