Skip to content

Commit

Permalink
fix: applied filter appenRow focus index (fix nhn#1819)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjh committed Feb 8, 2023
1 parent 86c3818 commit ba0349c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/toast-ui.grid/cypress/integration/data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ describe('appendRow()', () => {

cy.getCell(2, 'name').should('have.text', 'observable');
});

it('if a filter applied and focus option exist, set focus to the first cell of the inserted row', () => {
createGrid();
cy.gridInstance().invoke('appendRow', { name: 'Park', age: 15 });
cy.gridInstance().invoke('filter', 'name', [{ code: 'eq', value: 'Park' }]);
cy.gridInstance().invoke('appendRow', { name: 'Park', age: 30 }, { focus: true });

cy.gridInstance().invoke('getFocusedCell').should('eql', {
rowKey: 3,
columnName: 'name',
value: 'Park',
});
});
});

describe('prependRow()', () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/toast-ui.grid/src/grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
includes,
isEmpty,
isNil,
isNull,
} from './helper/common';
import { Observable, getOriginObject } from './helper/observable';
import { createEventBus, EventBus } from './event/eventBus';
Expand Down Expand Up @@ -1178,8 +1179,13 @@ export default class Grid implements TuiGrid {
}

if (options.focus) {
const rowIdx = isUndefined(options.at) ? this.getRowCount() - 1 : options.at;
this.focusAt(rowIdx, 0);
if (!isUndefined(options.at)) {
this.focusAt(options.at, 0);
} else if (isNull(this.store.data.filters)) {
this.focusAt(this.getRowCount() - 1, 0);
} else {
this.focusAt(this.store.data.filteredRawData.length - 1, 0);
}
}
}

Expand Down

0 comments on commit ba0349c

Please sign in to comment.