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: Fix sorting when it and filtering are changed at the same time (T1237863) #28532

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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
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
Loading