diff --git a/e2e/testcafe-devextreme/tests/dataGrid/stateStoring/stateStoring.ts b/e2e/testcafe-devextreme/tests/dataGrid/stateStoring/stateStoring.ts index 4fef2309d598..a1fd3fbf8dd1 100644 --- a/e2e/testcafe-devextreme/tests/dataGrid/stateStoring/stateStoring.ts +++ b/e2e/testcafe-devextreme/tests/dataGrid/stateStoring/stateStoring.ts @@ -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); @@ -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)); +}); diff --git a/packages/devextreme/js/__internal/grids/grid_core/state_storing/m_state_storing.ts b/packages/devextreme/js/__internal/grids/grid_core/state_storing/m_state_storing.ts index d2c1234c692d..926ee563a6e1 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/state_storing/m_state_storing.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/state_storing/m_state_storing.ts @@ -157,10 +157,9 @@ const stateStoring = (Base: ModuleType) => 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'); @@ -178,7 +177,9 @@ const stateStoring = (Base: ModuleType) => class StateSt } if (!this.option('selection.deferred')) { - this.option('selectedRowKeys', selectedRowKeys || []); + if (selectedRowKeys && selectedRowKeys.length !== 0) { + this.option('selectedRowKeys', selectedRowKeys || []); + } } // @ts-expect-error