Skip to content

Commit

Permalink
fix(grid): only operate selected data which is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
minlovehua committed Feb 21, 2025
1 parent b318b42 commit 52e959d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/grid/src/services/selection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,22 @@ export class AITableGridSelectionService {

selectCells(startCell: AIRecordFieldIdPath, endCell?: AIRecordFieldIdPath) {
const [startRecordId, startFieldId] = startCell;
const records = this.aiTable.context!.linearRows();
const fields = AITable.getVisibleFields(this.aiTable);
const visibleRecords = this.aiTable.context!.linearRows();
const visiblefields = AITable.getVisibleFields(this.aiTable);
const selectedCells = new Set<string>();

if (!endCell) {
selectedCells.add(`${startRecordId}:${startFieldId}`);
} else {
const [endRecordId, endFieldId] = endCell;

const startRowIndex = this.aiTable.context!.visibleRowsIndexMap().get(startRecordId)!;
const endRowIndex = this.aiTable.context!.visibleRowsIndexMap().get(endRecordId)!;
const startColIndex = this.aiTable.context!.visibleColumnsIndexMap().get(startFieldId)!;
const endColIndex = this.aiTable.context!.visibleColumnsIndexMap().get(endFieldId)!;
const recordsIndexMap = this.aiTable.context!.visibleRowsIndexMap();
const fieldsIndexMap = this.aiTable.context!.visibleColumnsIndexMap();

const startRowIndex = recordsIndexMap.get(startRecordId)!;
const endRowIndex = recordsIndexMap.get(endRecordId)!;
const startColIndex = fieldsIndexMap.get(startFieldId)!;
const endColIndex = fieldsIndexMap.get(endFieldId)!;

const minRowIndex = Math.min(startRowIndex, endRowIndex);
const maxRowIndex = Math.max(startRowIndex, endRowIndex);
Expand All @@ -122,7 +125,7 @@ export class AITableGridSelectionService {

for (let i = minRowIndex; i <= maxRowIndex; i++) {
for (let j = minColIndex; j <= maxColIndex; j++) {
selectedCells.add(`${records[i]._id}:${fields[j]._id}`);
selectedCells.add(`${visibleRecords[i]._id}:${visiblefields[j]._id}`);
}
}
}
Expand Down

0 comments on commit 52e959d

Please sign in to comment.