Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: applied filter appenRow focus index (fix #1819) #1854

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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