Skip to content

Commit b9a8270

Browse files
committed
add getRangeCellSelection instance method
1 parent f2a036e commit b9a8270

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

packages/ve-table/src/index.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,6 +3284,37 @@ export default {
32843284
}
32853285
},
32863286

3287+
/*
3288+
get range cell selection
3289+
*/
3290+
[INSTANCE_METHODS.GET_RANGE_CELL_SELECTION]() {
3291+
const {
3292+
cellSelectionData,
3293+
cellSelectionRangeData,
3294+
allRowKeys,
3295+
colgroups,
3296+
} = this;
3297+
3298+
const { rowKey, colKey } = cellSelectionData.currentCell;
3299+
3300+
if (!isEmptyValue(rowKey) && !isEmptyValue(colKey)) {
3301+
let selectionRangeKeys = getSelectionRangeKeys({
3302+
cellSelectionRangeData,
3303+
});
3304+
3305+
let selectionRangeIndexes = getSelectionRangeIndexes({
3306+
cellSelectionRangeData,
3307+
colgroups,
3308+
allRowKeys,
3309+
});
3310+
3311+
return {
3312+
selectionRangeKeys,
3313+
selectionRangeIndexes,
3314+
};
3315+
}
3316+
},
3317+
32873318
/*
32883319
set all cell selection and column to visible
32893320
*/

packages/ve-table/src/util/constant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ export const INSTANCE_METHODS = {
198198
SET_CELL_SELECTION: "setCellSelection",
199199
// set range cell selection
200200
SET_RANGE_CELL_SELECTION: "setRangeCellSelection",
201+
// get range cell selection
202+
GET_RANGE_CELL_SELECTION: "getRangeCellSelection",
201203
// set all cell selection
202204
SET_ALL_CELL_SELECTION: "setAllCellSelection",
203205
// hide columns by keys

tests/unit/specs/ve-table-cell-selection.spec.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,77 @@ describe("veTable cell selection", () => {
629629
});
630630
});
631631

632+
it("table instance: setAllCellSelection method", async () => {
633+
const wrapper = mount(veTable, {
634+
propsData: {
635+
columns: COLUMNS,
636+
tableData: TABLE_DATA,
637+
rowKeyFieldName: "rowKey",
638+
},
639+
});
640+
641+
wrapper.vm.setAllCellSelection();
642+
643+
await later();
644+
645+
expect(wrapper.vm.cellSelectionRangeData).toEqual({
646+
bottomRowKey: "5",
647+
leftColKey: "b",
648+
rightColKey: "d",
649+
topRowKey: "1",
650+
});
651+
});
652+
653+
it("table instance: getRangeCellSelection method", async () => {
654+
const wrapper = mount(veTable, {
655+
propsData: {
656+
columns: COLUMNS,
657+
tableData: TABLE_DATA,
658+
rowKeyFieldName: "rowKey",
659+
},
660+
});
661+
662+
wrapper.vm.setRangeCellSelection({
663+
startRowKey: "2",
664+
startColKey: "a",
665+
endRowKey: "5",
666+
endColKey: "c",
667+
isScrollToStartCell: true,
668+
});
669+
670+
await later();
671+
672+
const selectionTd = wrapper
673+
.findAll(".ve-table-body-tr")
674+
.at(1)
675+
.findAll(".ve-table-body-td")
676+
.at(0);
677+
678+
expect(selectionTd.classes()).toContain("ve-table-cell-selection");
679+
expect(wrapper.vm.cellSelectionRangeData).toEqual({
680+
bottomRowKey: "5",
681+
leftColKey: "a",
682+
rightColKey: "c",
683+
topRowKey: "2",
684+
});
685+
686+
const rangeCellSelection = wrapper.vm.getRangeCellSelection();
687+
expect(rangeCellSelection).toEqual({
688+
selectionRangeIndexes: {
689+
endColIndex: 2,
690+
endRowIndex: 4,
691+
startColIndex: 0,
692+
startRowIndex: 1,
693+
},
694+
selectionRangeKeys: {
695+
endColKey: "c",
696+
endRowKey: "5",
697+
startColKey: "a",
698+
startRowKey: "2",
699+
},
700+
});
701+
});
702+
632703
/* it("virtual scroll keyboard events", async () => {
633704
const mockFn = jest.fn();
634705

0 commit comments

Comments
 (0)