From d386c1355dea549b7082be558747c7eabe45e6be Mon Sep 17 00:00:00 2001 From: Alyar Date: Fri, 13 Dec 2024 18:27:48 +0400 Subject: [PATCH] DataGrid: Fix sorting when it and filtering are changed at the same time (T1237863) (#28545) Co-authored-by: Alyar <> --- .../m_columns_controller.ts | 12 +++-- ...237863_datagrid-grouping_and_filtering.png | Bin 0 -> 5248 bytes .../tests/dataGrid/grouping/grouping.ts | 39 ++++++++++++++++ ...1237863_datagrid-sorting_and_filtering.png | Bin 0 -> 4914 bytes .../tests/dataGrid/sorting/sorting.ts | 43 ++++++++++++++++++ 5 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 packages/devextreme/testing/testcafe/tests/dataGrid/grouping/etalons/T1237863_datagrid-grouping_and_filtering.png create mode 100644 packages/devextreme/testing/testcafe/tests/dataGrid/sorting/etalons/T1237863_datagrid-sorting_and_filtering.png diff --git a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/m_columns_controller.ts b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/m_columns_controller.ts index 8ad5de9dab8d..1c6c0a2bfe46 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/columns_controller/m_columns_controller.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/columns_controller/m_columns_controller.ts @@ -1259,7 +1259,6 @@ export class ColumnsController extends modules.Controller { public updateSortingGrouping(dataSource, fromDataSource?) { const that = this; - let sortParameters; let isColumnsChanged; const updateSortGroupParameterIndexes = function (columns, sortParameters, indexParameterName) { each(columns, (index, column) => { @@ -1296,10 +1295,14 @@ export class ColumnsController extends modules.Controller { }); }; if (dataSource) { - sortParameters = gridCoreUtils.normalizeSortingInfo(dataSource.sort()); + const sortParameters = gridCoreUtils.normalizeSortingInfo(dataSource.sort()); const groupParameters = gridCoreUtils.normalizeSortingInfo(dataSource.group()); const columnsGroupParameters = that.getGroupDataSourceParameters(); const columnsSortParameters = that.getSortDataSourceParameters(); + const changeTypes = this._columnChanges?.changeTypes; + const sortingChanged = !gridCoreUtils.equalSortParameters(sortParameters, columnsSortParameters); + const needToApplySortingFromDataSource = fromDataSource && !changeTypes?.sorting; + const needToApplyGroupingFromDataSource = fromDataSource && !changeTypes?.grouping; const groupingChanged = !gridCoreUtils.equalSortParameters(groupParameters, columnsGroupParameters, true); const groupExpandingChanged = !groupingChanged && !gridCoreUtils.equalSortParameters(groupParameters, columnsGroupParameters); @@ -1315,7 +1318,7 @@ export class ColumnsController extends modules.Controller { assignColumns(that, createColumnsFromOptions(that, that._columns)); } - if ((fromDataSource || (!columnsGroupParameters && !that._hasUserState)) && (groupingChanged || groupExpandingChanged)) { + if ((needToApplyGroupingFromDataSource || (!columnsGroupParameters && !that._hasUserState)) && (groupingChanged || groupExpandingChanged)) { /// #DEBUG that.__groupingUpdated = true; /// #ENDDEBUG @@ -1326,7 +1329,8 @@ export class ColumnsController extends modules.Controller { isColumnsChanged = true; } } - if ((fromDataSource || (!columnsSortParameters && !that._hasUserState)) && !gridCoreUtils.equalSortParameters(sortParameters, columnsSortParameters)) { + + if ((needToApplySortingFromDataSource || (!columnsSortParameters && !that._hasUserState)) && sortingChanged) { /// #DEBUG that.__sortingUpdated = true; /// #ENDDEBUG diff --git a/packages/devextreme/testing/testcafe/tests/dataGrid/grouping/etalons/T1237863_datagrid-grouping_and_filtering.png b/packages/devextreme/testing/testcafe/tests/dataGrid/grouping/etalons/T1237863_datagrid-grouping_and_filtering.png new file mode 100644 index 0000000000000000000000000000000000000000..e77ff373bc76488238a8c80654f420f9c6be8aa5 GIT binary patch literal 5248 zcmc&&c|4T+zn>N@q=l4JbdJh0?5rV;^fW*_X7akQU3qu^ZbkBqL3h zHraA)GaMuwlr8&Y=lA*2z4vv0_rC5u_uk*@b)P@RGvoO_&*%I3eBR6Fxu>tI!O70Y zj=^9!H7}^*F_^6>aDH#cHuyYDJ7)lYHfyRX8+mUU;|pxTVD{tCx391LoTFKrs{1CE zX+hYlDJ)23# z_&5%1->Fh^W0x>~{A!KkVB3KgF-5Z9O@V|fW z-aZ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*t?GVwaT8X2`Ss?AL(=N- zs-o$;*x-O(NV7u*4M_^-kWORhqhgy{uB!L%;oTnG`u}TQLfL}Dy*UVz_1RaJ$6iwr Oeb-deRi&z24*5I5_18H7 literal 0 HcmV?d00001 diff --git a/packages/devextreme/testing/testcafe/tests/dataGrid/grouping/grouping.ts b/packages/devextreme/testing/testcafe/tests/dataGrid/grouping/grouping.ts index 212975bcfe5b..11227b617c28 100644 --- a/packages/devextreme/testing/testcafe/tests/dataGrid/grouping/grouping.ts +++ b/packages/devextreme/testing/testcafe/tests/dataGrid/grouping/grouping.ts @@ -378,3 +378,42 @@ test('DataGrid loses grouping after the expandAll method if a grouped column has }, ], })); + +test('Grouping and filtering should be applied correctly when they change at runtime (T1237863)', async (t) => { + const dataGrid = new DataGrid('#container'); + const { takeScreenshot, compareResults } = createScreenshotsComparer(t); + + await t.expect(dataGrid.isReady()).ok(); + + await dataGrid.option({ + 'columns[2].groupIndex': 0, + filterValue: ['room', '=', '1'], + }); + + await t.expect(dataGrid.isReady()).ok(); + + await takeScreenshot('T1237863_datagrid-grouping_and_filtering.png', dataGrid.element); + + await t + .expect(compareResults.isValid()) + .ok(compareResults.errorMessages()); +}).before(() => createWidget('dxDataGrid', { + dataSource: [ + { + ID: 1, + FirstName: 'Bob', + room: 1, + }, + { + ID: 2, + FirstName: 'Alex', + room: 2, + }, + { + ID: 3, + FirstName: 'John', + room: 1, + }, + ], + keyExpr: 'ID', +})); diff --git a/packages/devextreme/testing/testcafe/tests/dataGrid/sorting/etalons/T1237863_datagrid-sorting_and_filtering.png b/packages/devextreme/testing/testcafe/tests/dataGrid/sorting/etalons/T1237863_datagrid-sorting_and_filtering.png new file mode 100644 index 0000000000000000000000000000000000000000..6c1cd564248e9e4ce51c439fdf7775b0d6f9d072 GIT binary patch literal 4914 zcmcgwcT^N<_APZ#fdO?DOoU+!WDo>Iq69^trAbYbTa=vCme@!z017Auf`BB+*+52u zAVCpnprIv+2x!xYfY5{{?JH)^{AT~!bAEev>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ubNg6GvE!mj=A;8 z#F^xqrsn61c{cYjSfErKkHq)$ literal 0 HcmV?d00001 diff --git a/packages/devextreme/testing/testcafe/tests/dataGrid/sorting/sorting.ts b/packages/devextreme/testing/testcafe/tests/dataGrid/sorting/sorting.ts index 6fde3381a4c1..d4b1fd2c82d6 100644 --- a/packages/devextreme/testing/testcafe/tests/dataGrid/sorting/sorting.ts +++ b/packages/devextreme/testing/testcafe/tests/dataGrid/sorting/sorting.ts @@ -87,3 +87,46 @@ test('Multiple sorting alphabetical icons should be correct in Fluent Theme (T12 }); }, ).after(async () => { await changeTheme(Themes.genericLight); }); + +test('Sorting and filtering should be applied correctly when they change at runtime (T1237863)', async (t) => { + const dataGrid = new DataGrid('#container'); + const { takeScreenshot, compareResults } = createScreenshotsComparer(t); + + await t.expect(dataGrid.isReady()).ok(); + + await dataGrid.option({ + 'columns[1].sortIndex': 0, + 'columns[1].sortOrder': 'desc', + filterValue: ['room', '=', '1'], + }); + + await t.expect(dataGrid.isReady()).ok(); + + await takeScreenshot('T1237863_datagrid-sorting_and_filtering.png', dataGrid.element); + + await t + .expect(compareResults.isValid()) + .ok(compareResults.errorMessages()); +}).before(() => createWidget('dxDataGrid', { + dataSource: [ + { + ID: 1, + FirstName: 'Bob', + room: 1, + }, + { + ID: 2, + FirstName: 'Alex', + room: 2, + }, + { + ID: 3, + FirstName: 'John', + room: 1, + }, + ], + keyExpr: 'ID', + sorting: { + mode: 'multiple', + }, +}));