Skip to content

Commit

Permalink
DataGrid: Fix sorting when it and filtering are changed at the same t…
Browse files Browse the repository at this point in the history
…ime (T1237863) (#28532)

Co-authored-by: Alyar <>
  • Loading branch information
Alyar666 authored Dec 11, 2024
1 parent 8ea8ffb commit f268b71
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions e2e/testcafe-devextreme/tests/dataGrid/grouping/grouping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,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',
}));
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions e2e/testcafe-devextreme/tests/dataGrid/sorting/sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
}));
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,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) => {
Expand Down Expand Up @@ -1304,10 +1303,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);

Expand All @@ -1323,7 +1326,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
Expand All @@ -1334,7 +1337,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
Expand Down

0 comments on commit f268b71

Please sign in to comment.