Skip to content

useGridSelection

Hook for programmatic selection control.

Must be used within a DataGrid component tree with the selection feature enabled. Uses React context, so it works reliably regardless of when the grid mounts.

useGridSelection(selector: string): SelectionMethods<TRow>
NameTypeDescription
selectorstringOptional CSS selector to target a specific grid element via
DOM query instead of using React context. Use when the component contains
multiple grids, e.g. 'tbw-grid.primary' or '#my-grid'.
import { useGridSelection } from '@toolbox-web/grid-react/features/selection';
function ExportSelectedButton() {
const { getSelection, clearSelection } = useGridSelection();
const handleExport = () => {
const selection = getSelection();
if (!selection) return;
// Derive rows from selection.ranges and grid.rows
clearSelection();
};
return <button onClick={handleExport}>Export Selected</button>;
}
AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt