Skip to content

Commit

Permalink
Merge pull request #375 from komarovalexander/dev
Browse files Browse the repository at this point in the history
Add SelectRows & DeselectRows
  • Loading branch information
komarovalexander authored Jan 26, 2024
2 parents ca36491 + 926d8fd commit 2450ff1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ka-table",
"version": "8.7.2",
"version": "8.8.0",
"license": "MIT",
"repository": "github:komarovalexander/ka-table",
"homepage": "https://komarovalexander.github.io/ka-table/#/overview",
Expand Down
6 changes: 6 additions & 0 deletions src/lib/Reducers/kaReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ const kaReducer: any = (props: ITableProps, action: any): ITableProps => {
}
case ActionType.SelectRow:
return { ...props, selectedRows: [...selectedRows, ...[action.rowKeyValue]] };
case ActionType.SelectRows:
return { ...props, selectedRows: [...selectedRows, ...action.rowsKeyValues] };
case ActionType.SelectRowsRange: {
const rowKeyValueTo = action.rowKeyValueTo;
if (rowKeyValueTo) {
Expand All @@ -332,6 +334,10 @@ const kaReducer: any = (props: ITableProps, action: any): ITableProps => {
const newSelectedRows = [...selectedRows].filter((s) => s !== action.rowKeyValue);
return { ...props, selectedRows: newSelectedRows };
}
case ActionType.DeselectRows: {
const newSelectedRows = [...selectedRows].filter((s) => !action.rowsKeyValues.includes(s));
return { ...props, selectedRows: newSelectedRows };
}
case ActionType.UpdateSortDirection:
const sortedColumns = getUpdatedSortedColumns(columns, action.columnKey, sortingMode);
return { ...props, columns: sortedColumns };
Expand Down
10 changes: 10 additions & 0 deletions src/lib/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export const deselectRow = (rowKeyValue: any) => ({
type: ActionType.DeselectRow,
});

export const deselectRows = (rowsKeyValues: any[]) => ({
rowsKeyValues,
type: ActionType.DeselectRows,
});

export const openEditor = (rowKeyValue: any, columnKey: string) => ({
columnKey,
rowKeyValue,
Expand Down Expand Up @@ -115,6 +120,11 @@ export const selectRow = (rowKeyValue: any) => ({
type: ActionType.SelectRow,
});

export const selectRows = (rowsKeyValues: any) => ({
rowsKeyValues,
type: ActionType.SelectRows,
});

export const selectRowsRange = (rowKeyValueFrom: any, rowKeyValueTo: any) => ({
rowKeyValueFrom,
rowKeyValueTo,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum ActionType {
DeselectAllRows = 'DeselectAllRows',
DeselectAllVisibleRows = 'DeselectAllVisibleRows',
DeselectRow = 'DeselectRow',
DeselectRows = 'DeselectRows',
GroupColumn = 'GroupColumn',
HideColumn = 'HideColumn',
HideDetailsRow = 'HideDetailsRow',
Expand Down Expand Up @@ -61,6 +62,7 @@ export enum ActionType {
SelectAllRows = 'SelectAllRows',
SelectAllVisibleRows = 'SelectAllVisibleRows',
SelectRow = 'SelectRow',
SelectRows = 'SelectRows',
SelectRowsRange = 'SelectRowsRange',
SelectSingleRow = 'SelectSingleRow',
SetFocused = 'SetFocused',
Expand Down

0 comments on commit 2450ff1

Please sign in to comment.