Skip to content

Commit

Permalink
fix: check/uncheck event emitted when multi check/uncheck via shift c…
Browse files Browse the repository at this point in the history
…lick
  • Loading branch information
jajugoguma committed Sep 14, 2023
1 parent 1037d31 commit 7c3dfd3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/toast-ui.grid/src/dispatch/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
isScrollPagination,
isFiltered,
getCreatedRowInfos,
getRowKeyByIndexWithPageRange,
} from '../query/data';
import {
updateSummaryValueByCell,
Expand Down Expand Up @@ -378,7 +379,8 @@ export function check(store: Store, rowKey: RowKey) {
/**
* Occurs when a checkbox in row header is checked
* @event Grid#check
* @property {number | string} rowKey - rowKey of the checked row
* @property {number | string} [rowKey] - rowKey of the checked row(when single check via click)
* @property {Array<number | string>} [rowKeys] - rowKeys of the checked rows(when multiple check via shift-click)
* @property {Grid} instance - Current grid instance
*/
eventBus.trigger('check', gridEvent);
Expand All @@ -403,7 +405,8 @@ export function uncheck(store: Store, rowKey: RowKey) {
/**
* Occurs when a checkbox in row header is unchecked
* @event Grid#uncheck
* @property {number | string} rowKey - rowKey of the unchecked row
* @property {number | string} [rowKey] - rowKey of the unchecked row(when single check via click)
* @property {Array<number | string>} [rowKeys] - rowKeys of the unchecked rows(when multiple unchecked via shift-click)
* @property {Grid} instance - Current grid instance
*/
eventBus.trigger('uncheck', gridEvent);
Expand All @@ -415,9 +418,10 @@ export function setCheckboxBetween(
startRowKey: RowKey,
endRowKey?: RowKey
) {
const { data } = store;
const { data, id } = store;
const { clickedCheckboxRowkey } = data;
const targetRowKey = endRowKey || clickedCheckboxRowkey;
const eventBus = getEventBus(id);

data.clickedCheckboxRowkey = startRowKey;

Expand All @@ -432,8 +436,17 @@ export function setCheckboxBetween(

const range = getIndexRangeOfCheckbox(store, startRowKey, targetRowKey);

const rowKeys: RowKey[] = [];
for (let i = range[0]; i < range[1]; i += 1) {
rowKeys.push(getRowKeyByIndexWithPageRange(data, i));
}

const gridEvent = new GridEvent({ rowKeys });

setRowsAttributeInRange(store, 'checked', value, range);
setCheckedAllRows(store);

eventBus.trigger(value ? 'check' : 'uncheck', gridEvent);
}

export function checkAll(store: Store, allPage?: boolean) {
Expand Down
1 change: 1 addition & 0 deletions packages/toast-ui.grid/types/event/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface GridEventProps {
nextValue?: CellValue;
event?: MouseEvent;
rowKey?: RowKey | null;
rowKeys?: RowKey[] | null;
columnName?: string | null;
prevRowKey?: RowKey | null;
prevColumnName?: string | null;
Expand Down

0 comments on commit 7c3dfd3

Please sign in to comment.