Skip to content

Commit d37d9f5

Browse files
committed
fix: set disableSelect when select range not work #5078
1 parent 3bb542e commit d37d9f5

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

packages/vtable/__tests__/listTable.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,58 @@ describe('listTable init test', () => {
196196
]);
197197
expect(listTable.getScrollTop()).toBe(scrollTop);
198198
});
199+
test('listTable drag select should stop before disabled merged last row', () => {
200+
const dragContainerDom: HTMLElement = createDiv();
201+
dragContainerDom.style.position = 'relative';
202+
dragContainerDom.style.width = '800px';
203+
dragContainerDom.style.height = '600px';
204+
const dragRecords = [
205+
{ a: 'r1', b: 1, c: 'x' },
206+
{ a: 'r2', b: 2, c: 'y' },
207+
{ a: 'r3', b: 3, c: 'z' },
208+
{ a: 'r4', b: 4, c: 'w' }
209+
];
210+
const dragTable = new ListTable({
211+
container: dragContainerDom,
212+
columns: [
213+
{ field: 'a', title: 'A', width: 120 },
214+
{ field: 'b', title: 'B', width: 120 },
215+
{ field: 'c', title: 'C', width: 120 }
216+
],
217+
records: dragRecords,
218+
bottomFrozenRowCount: 1,
219+
select: {
220+
disableSelect: (col, row, table) => row === table.rowCount - 1
221+
},
222+
customMergeCell: (col, row, table) => {
223+
if (row === table.rowCount - 1) {
224+
return {
225+
text: 'summary',
226+
range: {
227+
start: { col: 0, row: table.rowCount - 1 },
228+
end: { col: table.colCount - 1, row: table.rowCount - 1 }
229+
}
230+
};
231+
}
232+
}
233+
});
234+
235+
dragTable.stateManager.updateSelectPos(1, 2, false, false, false, false, false);
236+
dragTable.stateManager.updateInteractionState('grabing');
237+
dragTable.stateManager.updateSelectPos(1, dragTable.rowCount - 2, false, false, false, false, false);
238+
dragTable.stateManager.updateSelectPos(1, dragTable.rowCount - 1, false, false, false, false, false);
239+
dragTable.stateManager.endSelectCells(false, false);
240+
dragTable.stateManager.updateInteractionState('default');
241+
242+
expect(dragTable.getSelectedCellRanges()).toEqual([
243+
{
244+
start: { col: 1, row: 2 },
245+
end: { col: 1, row: dragTable.rowCount - 2 }
246+
}
247+
]);
248+
249+
dragTable.release();
250+
});
199251
test('listTable measureTextWidth', () => {
200252
const measureTextWdith = listTable.measureText("家里方大化工撒个福建师大看哈 fdsfgj! *-+&5%#.,'.,。、", {
201253
fontFamily: 'Arial',

packages/vtable/examples/list-analysis/list-aggregation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export function createTable() {
103103
field: 'salary',
104104
title: 'salary',
105105
width: 100,
106+
disableHeaderSelect: true,
107+
disableSelect: true,
106108
aggregation: [
107109
{
108110
aggregationType: AggregationType.MAX,

packages/vtable/src/event/listener/container-dom.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,9 @@ export function bindContainerDomListener(eventManager: EventManager) {
613613
const targetCol = table.getTargetColAtConsiderRightFrozen(selectX, considerFrozenX);
614614
const targetRow = table.getTargetRowAtConsiderBottomFrozen(selectY, considerFrozenY);
615615
if (!table.options.select?.disableDragSelect && isValid(targetCol) && isValid(targetRow)) {
616+
if (isCellDisableSelect(table, targetCol.col, targetRow.row)) {
617+
return;
618+
}
616619
table.stateManager.updateSelectPos(
617620
table.stateManager.select.selectInline === 'row' ? table.colCount - 1 : targetCol.col,
618621
table.stateManager.select.selectInline === 'col' ? table.rowCount - 1 : targetRow.row,

packages/vtable/src/state/select/update-position.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Scenegraph } from '../../scenegraph/scenegraph';
55
import type { SelectAllOnCtrlAOption } from '../../ts-types';
66
import { InteractionState } from '../../ts-types';
77
import type { StateManager } from '../state';
8+
import { isCellDisableSelect } from './is-cell-select-highlight';
89
/**
910
* @description: 更新select位置
1011
* @param {StateManager} state
@@ -350,6 +351,10 @@ export function updateSelectPosition(
350351
(interactionState === InteractionState.grabing || table.eventManager.isDraging) &&
351352
!table.stateManager.isResizeCol()
352353
) {
354+
if (col >= 0 && row >= 0 && isCellDisableSelect(table, col, row)) {
355+
scenegraph.updateNextFrame();
356+
return;
357+
}
353358
let extendSelectRange = isValid(skipBodyMerge) ? !skipBodyMerge : true;
354359
// 可能有cellPosStart从-1开始grabing的情况
355360
if (cellPos.col === -1) {

0 commit comments

Comments
 (0)