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

DataGrid - If a property is removed from the state object, it becomes null rather than taking the default value passed to the component (T1233556) #27802

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ const makeLocalStorageJsonInvalid = ClientFunction(() => {
window.localStorage.testStorageKey = '{]';
});

const localConfig = (rows): any => ({
dataSource: Array.from(new Array(rows).keys()).map((i) => ({ id: i })),
width: '100%',
keyExpr: 'id',
showBorders: true,
selectedRowKeys: [0],
selection: { mode: 'multiple' },
stateStoring: {
enabled: true,
storageKey: 'storage_custom',
},
columns: [{ dataField: 'id' }, 'column2', 'column3', 'column4', 'column5'],
});

test('The Grid should load if JSON in localStorage is invalid and stateStoring enabled', async (t) => {
const dataGrid = new DataGrid(GRID_CONTAINER);
const secondCell = dataGrid.getDataCell(1, 1);
Expand Down Expand Up @@ -82,3 +96,23 @@ test('The rows should render correctly when cellTemplates are used and the selec
// simulating async rendering in React
await makeRowsViewTemplatesAsync(GRID_CONTAINER);
});

// T1233556
test('Should select selectedRowKeys value if state.selectedRowKeys is null, undefined, or empty array', async (t) => {
const dataGrid = new DataGrid(GRID_CONTAINER);

await t
.click(dataGrid.getDataCell(0, 0).element());

await t
.eval(() => location.reload());

await createWidget('dxDataGrid', localConfig(10));

await t
.expect(dataGrid.getDataRow(0).isSelected)
.ok();

}).before(async () => {
await createWidget('dxDataGrid', localConfig(10));
});
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ const stateStoring = (Base: ModuleType<StateStoringController>) => class StateSt
* @extended: TreeList's state_storing
*/
protected applyState(state) {
const { allowedPageSizes } = state;
const { searchText } = state;
const { selectedRowKeys } = state;
const { selectionFilter } = state;
const {
allowedPageSizes, searchText, selectedRowKeys, selectionFilter,
} = state;
const scrollingMode = this.option('scrolling.mode');
const isVirtualScrollingMode = scrollingMode === 'virtual' || scrollingMode === 'infinite';
const showPageSizeSelector = this.option('pager.visible') === true && this.option('pager.showPageSizeSelector');
Expand All @@ -178,7 +177,9 @@ const stateStoring = (Base: ModuleType<StateStoringController>) => class StateSt
}

if (!this.option('selection.deferred')) {
this.option('selectedRowKeys', selectedRowKeys || []);
if (selectedRowKeys && selectedRowKeys.length !== 0) {
this.option('selectedRowKeys', selectedRowKeys || []);
}
}

// @ts-expect-error
Expand Down
Loading