@omnigrid/selection-plugin 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,6 +28,7 @@ import { SelectionPlugin } from "@omnigrid/selection-plugin";
28
28
 
29
29
  const plugin = new SelectionPlugin({
30
30
  mode: "multiple",
31
+ groupSelection: "filteredDescendants",
31
32
  onSelectionChange: ({ selectedRowIds, selectedRows }) => {
32
33
  console.log("Selected count:", selectedRows.length);
33
34
  console.log("Selected IDs:", selectedRowIds);
@@ -43,6 +44,14 @@ const selection = plugin.getSelectionState();
43
44
  IDs and row records. `getSelectedRowIds()`, `getSelectedRows()`, and
44
45
  `getSelectionState()` provide synchronous access to the current selection.
45
46
 
47
+ When used with a row-grouping plugin, `groupSelection` controls the group
48
+ checkbox behavior. `"descendants"` selects every selectable leaf row in the
49
+ group, including filtered-out rows; `"filteredDescendants"` limits selection
50
+ to leaves that remain after filtering. Group checkboxes show an indeterminate
51
+ state when only some selectable descendants are selected. The default,
52
+ `"none"`, preserves the regular row-only selection behavior, and group
53
+ selection is available only in `"multiple"` mode.
54
+
46
55
  ## Links
47
56
 
48
57
  - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/plugins/base/selection
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { CheckboxRenderParams, GridApi, GridPlugin, RowId, RowRenderParams } from "@omnigrid/core";
2
- /** Selection behavior supported by the plugin. */
3
- export type SelectionMode = "single" | "multiple";
1
+ import type { GridApi, GridPlugin, RowId, RowRenderParams } from "@omnigrid/core";
2
+ import type { GroupSelectionMode, SelectionMode, SelectionPluginOptions, SelectionRenderer, SelectionRendererParams, SelectionState } from "./types";
3
+ export type { GroupSelectionMode, SelectionMode, SelectionPluginOptions, SelectionRenderer, SelectionRendererParams, SelectionState, };
4
4
  /**
5
5
  * CSS class applied to selected rows. The concrete selected-row color is
6
6
  * owned by the active theme (e.g. `@omnigrid/default-theme` defines
@@ -9,49 +9,6 @@ export type SelectionMode = "single" | "multiple";
9
9
  export declare const SELECTED_ROW_CLASS = "omnigrid-row-selected";
10
10
  /** Applied to rows rejected by `isRowSelectable`; themes supply muted colors. */
11
11
  export declare const UNSELECTABLE_ROW_CLASS = "omnigrid-row-unselectable";
12
- /** Values provided to a custom checkbox renderer. */
13
- export interface SelectionRendererParams<T> extends CheckboxRenderParams {
14
- /** Row data for a row checkbox; absent for the header checkbox. */
15
- data?: T;
16
- /** Row identifier for a row checkbox. */
17
- rowId?: RowId;
18
- /** Row index for a row checkbox. */
19
- index?: number;
20
- /** Whether the renderer is being called for the header checkbox. */
21
- header: boolean;
22
- }
23
- /** Renderer used to customize selection checkboxes. */
24
- export type SelectionRenderer<T> = (params: SelectionRendererParams<T>) => unknown;
25
- /** Configuration for the selection plugin. */
26
- export interface SelectionPluginOptions<T> {
27
- /** Supports selecting one row or multiple rows. @default "single" */
28
- mode?: SelectionMode;
29
- /** Restricts selection changes to checkbox interaction. @default false */
30
- checkboxOnly?: boolean;
31
- /** In multiple mode, clicking a row replaces the current selection. @default false */
32
- replaceSelectionOnClick?: boolean;
33
- /** Adds a checkbox to each row. @default false */
34
- showRowCheckboxes?: boolean;
35
- /** Adds a select-all checkbox to the selection column header. @default false */
36
- showHeaderCheckbox?: boolean;
37
- /** Determines whether a row can be selected. */
38
- isRowSelectable?: (row: T, index: number) => boolean;
39
- /** Renders checkbox UI; defaults to the OmniGrid checkbox renderer. */
40
- checkboxRenderer?: SelectionRenderer<T>;
41
- /** Called when the selected rows change. */
42
- onSelectionChange?: (state: SelectionState<T>) => void;
43
- /** ID for the automatically inserted checkbox column. @default "__omnigrid_selection__" */
44
- selectionColumnId?: string;
45
- /** Width in pixels of the automatically inserted checkbox column. @default 44 */
46
- selectionColumnWidth?: number;
47
- }
48
- /** Selected row identifiers and their corresponding row data. */
49
- export interface SelectionState<T> {
50
- /** IDs of selected rows. */
51
- selectedRowIds: RowId[];
52
- /** Data objects for selected rows. */
53
- selectedRows: T[];
54
- }
55
12
  /** Adds row selection and optional checkbox controls to a grid. */
56
13
  export declare class SelectionPlugin<T> implements GridPlugin<T> {
57
14
  readonly name = "@omnigrid/selection-plugin";
@@ -59,6 +16,7 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
59
16
  private mode;
60
17
  private checkboxOnly;
61
18
  private replaceSelectionOnClick;
19
+ private groupSelection;
62
20
  private showRowCheckboxes;
63
21
  private showHeaderCheckbox;
64
22
  private isRowSelectable;
@@ -69,6 +27,7 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
69
27
  private readonly selectedRowIds;
70
28
  private anchorIndex?;
71
29
  private unregisterRowClick?;
30
+ private unregisterMethods?;
72
31
  constructor(options?: SelectionPluginOptions<T>);
73
32
  register(api: GridApi<T>): () => void;
74
33
  /**
@@ -110,8 +69,13 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
110
69
  ctrlKey?: boolean;
111
70
  }): void;
112
71
  /** Returns selection-related CSS classes for a row. */
113
- getRowClass({ id, index, data }: RowRenderParams<T>): string | undefined;
72
+ getRowClass(params: RowRenderParams<T>): string | undefined;
114
73
  private handleRowClick;
74
+ private toggleStableRow;
75
+ private getRowByStableId;
76
+ private getSelectionRowId;
77
+ private getCheckboxState;
78
+ private toggleGroupSelection;
115
79
  private applySelection;
116
80
  private updateColumns;
117
81
  private renderCheckbox;
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ export class SelectionPlugin {
18
18
  this.mode = options.mode ?? "single";
19
19
  this.checkboxOnly = options.checkboxOnly ?? false;
20
20
  this.replaceSelectionOnClick = options.replaceSelectionOnClick ?? false;
21
+ this.groupSelection = options.groupSelection ?? "none";
21
22
  this.showRowCheckboxes = options.showRowCheckboxes ?? false;
22
23
  this.showHeaderCheckbox = options.showHeaderCheckbox ?? false;
23
24
  this.isRowSelectable = options.isRowSelectable ?? (() => true);
@@ -29,13 +30,33 @@ export class SelectionPlugin {
29
30
  register(api) {
30
31
  this.api = api;
31
32
  this.unregisterRowClick = api.on("rowClick", (event) => this.handleRowClick(event));
33
+ this.unregisterMethods = api.registerMethods({
34
+ selectRow: (rowId) => {
35
+ this.selectedRowIds.add(rowId);
36
+ this.refresh();
37
+ },
38
+ deselectRow: (rowId) => {
39
+ this.selectedRowIds.delete(rowId);
40
+ this.refresh();
41
+ },
42
+ getSelection: () => this.getSelectionState(),
43
+ clearSelection: () => this.clearSelection(),
44
+ });
45
+ api.setState((prev) => ({ ...prev, selection: this.getSelectionState() }));
32
46
  this.updateColumns();
33
47
  return () => {
34
48
  this.unregisterRowClick?.();
35
49
  this.unregisterRowClick = undefined;
36
- const api = this.api;
37
- if (api && !api.isDestroyed()) {
38
- api.setColumns(api.getState().columns.filter((column) => column.id !== this.selectionColumnId));
50
+ this.unregisterMethods?.();
51
+ this.unregisterMethods = undefined;
52
+ const targetApi = this.api;
53
+ if (targetApi && !targetApi.isDestroyed()) {
54
+ targetApi.setColumns(targetApi.getState().columns.filter((column) => column.id !== this.selectionColumnId));
55
+ targetApi.setState((prev) => {
56
+ const next = { ...prev };
57
+ delete next.selection;
58
+ return next;
59
+ });
39
60
  }
40
61
  this.selectedRowIds.clear();
41
62
  this.anchorIndex = undefined;
@@ -56,6 +77,9 @@ export class SelectionPlugin {
56
77
  getSelectedRows() {
57
78
  if (!this.api)
58
79
  return [];
80
+ if (this.groupSelection !== "none" && this.api.getRowHierarchy()) {
81
+ return this.api.getState().data.filter((row, index) => this.selectedRowIds.has(this.api.getRowId(row, index)));
82
+ }
59
83
  return this.api.getProcessedData().filter((row, index) => this.selectedRowIds.has(this.api.getRowId(row, index)));
60
84
  }
61
85
  /**
@@ -107,19 +131,130 @@ export class SelectionPlugin {
107
131
  this.applySelection(rowId, index, modifiers);
108
132
  }
109
133
  /** Returns selection-related CSS classes for a row. */
110
- getRowClass({ id, index, data }) {
134
+ getRowClass(params) {
135
+ const { id, index } = params;
136
+ const data = params.rowType === "leaf" ? params.data : undefined;
137
+ const checkboxState = this.getCheckboxState(id, index, data);
111
138
  const classes = [];
112
- if (this.selectedRowIds.has(id))
113
- classes.push(SELECTED_ROW_CLASS);
114
- if (!this.isRowSelectable(data, index))
115
- classes.push(UNSELECTABLE_ROW_CLASS);
139
+ if (checkboxState.group) {
140
+ if (this.mode !== "multiple" || this.groupSelection === "none")
141
+ return undefined;
142
+ if (checkboxState.checked)
143
+ classes.push(SELECTED_ROW_CLASS);
144
+ if (checkboxState.disabled)
145
+ classes.push(UNSELECTABLE_ROW_CLASS);
146
+ }
147
+ else {
148
+ if (this.selectedRowIds.has(id))
149
+ classes.push(SELECTED_ROW_CLASS);
150
+ if (data !== undefined && !this.isRowSelectable(data, index))
151
+ classes.push(UNSELECTABLE_ROW_CLASS);
152
+ }
116
153
  return classes.length > 0 ? classes.join(" ") : undefined;
117
154
  }
118
155
  handleRowClick(event) {
119
156
  if (this.checkboxOnly)
120
157
  return;
158
+ const hierarchy = this.api?.getRowHierarchy();
159
+ if (hierarchy) {
160
+ if (hierarchy.getLeafRowIds(event.id, "all") !== undefined)
161
+ return;
162
+ const row = this.getRowByStableId(event.id);
163
+ if (!row || !this.isRowSelectable(row.data, row.index))
164
+ return;
165
+ this.toggleStableRow(event.id, event, row.index);
166
+ return;
167
+ }
121
168
  this.applySelection(event.id, event.index, event);
122
169
  }
170
+ toggleStableRow(rowId, modifiers, index) {
171
+ if (this.mode === "single") {
172
+ if (!this.replaceSelectionOnClick && this.selectedRowIds.has(rowId) && !modifiers.shiftKey) {
173
+ this.selectedRowIds.delete(rowId);
174
+ }
175
+ else {
176
+ this.selectedRowIds.clear();
177
+ this.selectedRowIds.add(rowId);
178
+ }
179
+ }
180
+ else if (this.selectedRowIds.has(rowId)) {
181
+ this.selectedRowIds.delete(rowId);
182
+ }
183
+ else {
184
+ this.selectedRowIds.add(rowId);
185
+ }
186
+ this.anchorIndex = index;
187
+ this.refresh();
188
+ }
189
+ getRowByStableId(rowId) {
190
+ if (!this.api)
191
+ return undefined;
192
+ const rows = this.api.getState().data;
193
+ for (let index = 0; index < rows.length; index += 1) {
194
+ if (this.api.getRowId(rows[index], index) === rowId)
195
+ return { data: rows[index], index };
196
+ }
197
+ return undefined;
198
+ }
199
+ getSelectionRowId(row, index) {
200
+ if (!this.api)
201
+ return index;
202
+ const sourceIndex = this.api.getRowHierarchy() ? this.api.getState().data.indexOf(row) : -1;
203
+ return this.api.getRowId(row, sourceIndex >= 0 ? sourceIndex : index);
204
+ }
205
+ getCheckboxState(rowId, index, data) {
206
+ const hierarchy = this.api?.getRowHierarchy();
207
+ const allDescendants = hierarchy?.getLeafRowIds(rowId, "all");
208
+ const isGroup = allDescendants !== undefined;
209
+ if (!isGroup) {
210
+ const row = hierarchy ? this.getRowByStableId(rowId) : data !== undefined ? { data, index } : undefined;
211
+ const selectable = row !== undefined && this.isRowSelectable(row.data, row.index);
212
+ return {
213
+ checked: this.selectedRowIds.has(rowId),
214
+ indeterminate: false,
215
+ disabled: !selectable,
216
+ group: false,
217
+ rowIds: selectable ? [rowId] : [],
218
+ data: row?.data ?? data,
219
+ index: row?.index ?? index,
220
+ };
221
+ }
222
+ if (this.mode !== "multiple" || this.groupSelection === "none" || !hierarchy) {
223
+ return { checked: false, indeterminate: false, disabled: true, group: true, rowIds: [] };
224
+ }
225
+ const scope = this.groupSelection === "descendants" ? "all" : "filtered";
226
+ const descendants = scope === "all" ? (allDescendants ?? []) : (hierarchy.getLeafRowIds(rowId, "filtered") ?? []);
227
+ const sourceRows = scope === "all" ? (this.api?.getState().data ?? []) : (this.api?.getFilteredData() ?? []);
228
+ const selectableIds = [];
229
+ sourceRows.forEach((row, rowIndex) => {
230
+ const rawIndex = this.api?.getState().data.indexOf(row) ?? -1;
231
+ const sourceIndex = rawIndex >= 0 ? rawIndex : rowIndex;
232
+ const leafId = this.api?.getRowId(row, sourceIndex);
233
+ if (leafId !== undefined && descendants.includes(leafId) && this.isRowSelectable(row, rowIndex))
234
+ selectableIds.push(leafId);
235
+ });
236
+ const selectedCount = selectableIds.filter((leafId) => this.selectedRowIds.has(leafId)).length;
237
+ const checked = selectableIds.length > 0 && selectedCount === selectableIds.length;
238
+ return {
239
+ checked,
240
+ indeterminate: selectedCount > 0 && !checked,
241
+ disabled: selectableIds.length === 0,
242
+ group: true,
243
+ rowIds: selectableIds,
244
+ };
245
+ }
246
+ toggleGroupSelection(rowIds) {
247
+ if (rowIds.length === 0)
248
+ return;
249
+ const allSelected = rowIds.every((rowId) => this.selectedRowIds.has(rowId));
250
+ rowIds.forEach((rowId) => {
251
+ if (allSelected)
252
+ this.selectedRowIds.delete(rowId);
253
+ else
254
+ this.selectedRowIds.add(rowId);
255
+ });
256
+ this.refresh();
257
+ }
123
258
  applySelection(rowId, index, modifiers) {
124
259
  if (!this.api)
125
260
  return;
@@ -171,7 +306,6 @@ export class SelectionPlugin {
171
306
  this.api.setColumns(columns);
172
307
  return;
173
308
  }
174
- const hasPinnedLeft = columns.some((column) => column.pinned === "left");
175
309
  const selectionColumn = {
176
310
  id: this.selectionColumnId,
177
311
  header: "",
@@ -181,12 +315,8 @@ export class SelectionPlugin {
181
315
  sortable: false,
182
316
  stopHeaderClick: true,
183
317
  stopRowClick: true,
184
- // The checkbox column must stay in view while scrolling horizontally.
185
- // When the table already has left-pinned columns, pin the checkbox
186
- // column to the left (as the very first pinned column) so it never
187
- // scrolls away together with its pinned peers. With no left-pinned
188
- // columns the checkbox column stays as the first scrollable column.
189
- pinned: hasPinnedLeft ? "left" : undefined,
318
+ // The checkbox column must always stay pinned to the left.
319
+ pinned: "left",
190
320
  headerRenderer: () => this.renderCheckbox({
191
321
  checked: this.isAllSelectableRowsSelected(),
192
322
  indeterminate: this.hasSomeSelectableRowsSelected() && !this.isAllSelectableRowsSelected(),
@@ -195,17 +325,43 @@ export class SelectionPlugin {
195
325
  header: true,
196
326
  onChange: (event) => this.toggleAll(event),
197
327
  }),
198
- cellRenderer: ({ data, id, index }) => this.renderCheckbox({
199
- checked: id !== undefined && this.selectedRowIds.has(id),
200
- indeterminate: false,
201
- disabled: index === undefined || !this.isRowSelectable(data, index),
202
- ariaLabel: "Select row",
203
- data,
204
- rowId: id,
205
- index,
206
- header: false,
207
- onChange: (event) => id !== undefined && index !== undefined && this.toggleRow(id, index, event),
208
- }),
328
+ cellRenderer: ({ data, id, index }) => {
329
+ if (id === undefined || index === undefined) {
330
+ return this.renderCheckbox({
331
+ checked: false,
332
+ indeterminate: false,
333
+ disabled: true,
334
+ ariaLabel: "Select row",
335
+ header: false,
336
+ onChange: () => { },
337
+ });
338
+ }
339
+ const checkboxState = this.getCheckboxState(id, index, data);
340
+ if (checkboxState.group && (this.mode !== "multiple" || this.groupSelection === "none"))
341
+ return "";
342
+ return this.renderCheckbox({
343
+ checked: checkboxState.checked,
344
+ indeterminate: checkboxState.indeterminate,
345
+ disabled: checkboxState.disabled,
346
+ ariaLabel: checkboxState.group ? "Select group" : "Select row",
347
+ data: checkboxState.group ? undefined : checkboxState.data,
348
+ rowId: id,
349
+ index: checkboxState.index,
350
+ header: false,
351
+ group: checkboxState.group,
352
+ onChange: (event) => {
353
+ if (checkboxState.group) {
354
+ this.toggleGroupSelection(checkboxState.rowIds);
355
+ }
356
+ else if (this.api?.getRowHierarchy()) {
357
+ this.toggleStableRow(id, event, checkboxState.index ?? index);
358
+ }
359
+ else {
360
+ this.toggleRow(id, index, event);
361
+ }
362
+ },
363
+ });
364
+ },
209
365
  };
210
366
  this.api.setColumns([selectionColumn, ...columns]);
211
367
  }
@@ -225,12 +381,14 @@ export class SelectionPlugin {
225
381
  const processedData = this.api.getProcessedData();
226
382
  const selectableRows = processedData.filter((row, index) => this.isRowSelectable(row, index));
227
383
  return (selectableRows.length > 0 &&
228
- processedData.every((row, index) => !this.isRowSelectable(row, index) || this.selectedRowIds.has(this.api.getRowId(row, index))));
384
+ processedData.every((row, index) => !this.isRowSelectable(row, index) || this.selectedRowIds.has(this.getSelectionRowId(row, index))));
229
385
  }
230
386
  hasSomeSelectableRowsSelected() {
231
387
  if (!this.api)
232
388
  return false;
233
- return this.api.getProcessedData().some((row, index) => this.isRowSelectable(row, index) && this.selectedRowIds.has(this.api.getRowId(row, index)));
389
+ return this.api
390
+ .getProcessedData()
391
+ .some((row, index) => this.isRowSelectable(row, index) && this.selectedRowIds.has(this.getSelectionRowId(row, index)));
234
392
  }
235
393
  toggleAll(modifiers) {
236
394
  if (!this.api)
@@ -239,13 +397,13 @@ export class SelectionPlugin {
239
397
  if (this.isAllSelectableRowsSelected()) {
240
398
  processedData.forEach((row, index) => {
241
399
  if (this.isRowSelectable(row, index))
242
- this.selectedRowIds.delete(this.api.getRowId(row, index));
400
+ this.selectedRowIds.delete(this.getSelectionRowId(row, index));
243
401
  });
244
402
  }
245
403
  else {
246
404
  processedData.forEach((row, index) => {
247
405
  if (this.isRowSelectable(row, index))
248
- this.selectedRowIds.add(this.api.getRowId(row, index));
406
+ this.selectedRowIds.add(this.getSelectionRowId(row, index));
249
407
  });
250
408
  }
251
409
  this.refresh();
@@ -253,6 +411,7 @@ export class SelectionPlugin {
253
411
  refresh() {
254
412
  if (!this.api || this.api.isDestroyed())
255
413
  return;
414
+ this.api.setState((prev) => ({ ...prev, selection: this.getSelectionState() }));
256
415
  this.api.refresh();
257
416
  this.onSelectionChange?.(this.getSelectionState());
258
417
  }
@@ -262,7 +421,7 @@ export class SelectionPlugin {
262
421
  const processedData = this.api.getProcessedData();
263
422
  let hasChanges = false;
264
423
  for (const rowId of this.selectedRowIds) {
265
- const index = processedData.findIndex((row, idx) => this.api.getRowId(row, idx) === rowId);
424
+ const index = processedData.findIndex((row, idx) => this.getSelectionRowId(row, idx) === rowId);
266
425
  const row = index !== -1 ? processedData[index] : undefined;
267
426
  if (row && index !== -1 && !this.isRowSelectable(row, index)) {
268
427
  this.selectedRowIds.delete(rowId);
@@ -284,6 +443,8 @@ export class SelectionPlugin {
284
443
  this.checkboxOnly = newOptions.checkboxOnly;
285
444
  if (newOptions.replaceSelectionOnClick !== undefined)
286
445
  this.replaceSelectionOnClick = newOptions.replaceSelectionOnClick;
446
+ if (newOptions.groupSelection !== undefined)
447
+ this.groupSelection = newOptions.groupSelection;
287
448
  if (newOptions.showRowCheckboxes !== undefined)
288
449
  this.showRowCheckboxes = newOptions.showRowCheckboxes;
289
450
  if (newOptions.showHeaderCheckbox !== undefined)
@@ -0,0 +1,68 @@
1
+ import type { CheckboxRenderParams, RowId } from "@omnigrid/core";
2
+ /** Selection behavior supported by the plugin. */
3
+ export type SelectionMode = "single" | "multiple";
4
+ /** Controls whether group checkboxes select their descendants. @api */
5
+ export type GroupSelectionMode = "none" | "descendants" | "filteredDescendants";
6
+ /** Values provided to a custom checkbox renderer. */
7
+ export interface SelectionRendererParams<T> extends CheckboxRenderParams {
8
+ /** Row data for a row checkbox; absent for the header checkbox. */
9
+ data?: T;
10
+ /** Row identifier for a row checkbox. */
11
+ rowId?: RowId;
12
+ /** Row index for a row checkbox. */
13
+ index?: number;
14
+ /** Whether the renderer is being called for the header checkbox. */
15
+ header: boolean;
16
+ /** Whether the row checkbox represents a composite row. */
17
+ group?: boolean;
18
+ }
19
+ /** Renderer used to customize selection checkboxes. */
20
+ export type SelectionRenderer<T> = (params: SelectionRendererParams<T>) => unknown;
21
+ /** Configuration for the selection plugin. */
22
+ export interface SelectionPluginOptions<T> {
23
+ /** Supports selecting one row or multiple rows. @default "single" */
24
+ mode?: SelectionMode;
25
+ /** Restricts selection changes to checkbox interaction. @default false */
26
+ checkboxOnly?: boolean;
27
+ /** In multiple mode, clicking a row replaces the current selection. @default false */
28
+ replaceSelectionOnClick?: boolean;
29
+ /** Enables group checkbox selection in multiple mode. @default "none" */
30
+ groupSelection?: GroupSelectionMode;
31
+ /** Adds a checkbox to each row. @default false */
32
+ showRowCheckboxes?: boolean;
33
+ /** Adds a select-all checkbox to the selection column header. @default false */
34
+ showHeaderCheckbox?: boolean;
35
+ /** Determines whether a row can be selected. */
36
+ isRowSelectable?: (row: T, index: number) => boolean;
37
+ /** Renders checkbox UI; defaults to the OmniGrid checkbox renderer. */
38
+ checkboxRenderer?: SelectionRenderer<T>;
39
+ /** Called when the selected rows change. */
40
+ onSelectionChange?: (state: SelectionState<T>) => void;
41
+ /** ID for the automatically inserted checkbox column. @default "__omnigrid_selection__" */
42
+ selectionColumnId?: string;
43
+ /** Width in pixels of the automatically inserted checkbox column. @default 44 */
44
+ selectionColumnWidth?: number;
45
+ }
46
+ /** Selected row identifiers and their corresponding row data. */
47
+ export interface SelectionState<T> {
48
+ /** IDs of selected rows. */
49
+ selectedRowIds: RowId[];
50
+ /** Data objects for selected rows. */
51
+ selectedRows: T[];
52
+ }
53
+ declare module "@omnigrid/core" {
54
+ interface PluginStateExtensions<T> {
55
+ /** Active selection state. */
56
+ selection?: SelectionState<T>;
57
+ }
58
+ interface PluginApiExtensions<T> {
59
+ /** Selects a row by id. */
60
+ selectRow?: (rowId: RowId) => void;
61
+ /** Deselects a row by id. */
62
+ deselectRow?: (rowId: RowId) => void;
63
+ /** Returns the current selection state. */
64
+ getSelection?: () => SelectionState<T>;
65
+ /** Clears the current selection. */
66
+ clearSelection?: () => void;
67
+ }
68
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/selection-plugin",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Headless row selection plugin for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",