Skip to content

Commit 4ac0d56

Browse files
authored
T1331971: DataGrid - Filter Panel and Filter Row values are not synchronized when applyFilter="onClick" (DevExpress#34405)
1 parent a5b7144 commit 4ac0d56

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

packages/devextreme/js/__internal/grids/grid_core/filter/__tests__/m_filter_row.integration.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@jest/globals';
66
import type { EditorPreparingEvent } from '@js/ui/data_grid';
77
import { TagBoxModel } from '@ts/ui/__tests__/__mock__/model/tag_box';
8+
import { TextBoxModel } from '@ts/ui/__tests__/__mock__/model/textbox';
89

910
import {
1011
afterTest,
@@ -68,4 +69,54 @@ describe('FilterRow', () => {
6869
expect(tagBox.getTags()).toHaveLength(2);
6970
});
7071
});
72+
73+
describe('sync with filter panel when applyFilter is onClick (T1331971)', () => {
74+
it('should update the filter row editor when the condition is changed via the filter panel', async () => {
75+
const { component, instance } = await createDataGrid({
76+
dataSource: [
77+
{ id: 1, city: 'Las Vegas' },
78+
{ id: 2, city: 'San Jose' },
79+
],
80+
filterRow: { visible: true, applyFilter: 'onClick' },
81+
filterPanel: { visible: true },
82+
columns: ['city'],
83+
});
84+
85+
await flushAsync();
86+
87+
instance.option('filterValue', ['city', 'contains', 'Las']);
88+
await flushAsync();
89+
90+
instance.option('filterValue', ['city', 'contains', 'San']);
91+
await flushAsync();
92+
93+
const editor = component.getFilterRow().getFilterCell(0).getEditor(TextBoxModel);
94+
95+
expect(editor.getInput().value).toBe('San');
96+
});
97+
98+
it('should clear the filter row editor when the filter is reset via the filter panel', async () => {
99+
const { component, instance } = await createDataGrid({
100+
dataSource: [
101+
{ id: 1, city: 'Las Vegas' },
102+
{ id: 2, city: 'San Jose' },
103+
],
104+
filterRow: { visible: true, applyFilter: 'onClick' },
105+
filterPanel: { visible: true },
106+
columns: ['city'],
107+
});
108+
109+
await flushAsync();
110+
111+
instance.option('filterValue', ['city', 'contains', 'Las']);
112+
await flushAsync();
113+
114+
instance.option('filterValue', null as any);
115+
await flushAsync();
116+
117+
const editor = component.getFilterRow().getFilterCell(0).getEditor(TextBoxModel);
118+
119+
expect(editor.getInput().value).toBe('');
120+
});
121+
});
71122
});

packages/devextreme/js/__internal/grids/grid_core/filter/m_filter_sync.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ const getConditionFromHeaderFilter = function (column) {
101101
canSyncHeaderFilterWithFilterRow(column)
102102
&& !Array.isArray(filterValues[0])
103103
)) {
104-
column.filterType === FILTER_TYPES_EXCLUDE ? selectedOperation = '<>' : selectedOperation = '=';
104+
selectedOperation = column.filterType === FILTER_TYPES_EXCLUDE ? '<>' : '=';
105105
// eslint-disable-next-line prefer-destructuring
106106
value = filterValues[0];
107107
} else {
108-
column.filterType === FILTER_TYPES_EXCLUDE ? selectedOperation = 'noneof' : selectedOperation = 'anyof';
108+
selectedOperation = column.filterType === FILTER_TYPES_EXCLUDE ? 'noneof' : 'anyof';
109109
value = filterValues;
110110
}
111111
return [getColumnIdentifier(column), selectedOperation, value];
@@ -122,7 +122,7 @@ const updateFilterRowCondition = function (columnsController, column, condition)
122122
const filterValue = condition?.[2];
123123
const filterOperations = column.filterOperations || column.defaultFilterOperations;
124124

125-
const selectedOperationExists = !filterOperations || filterOperations.indexOf(selectedFilterOperation) >= 0;
125+
const selectedOperationExists = !filterOperations || filterOperations.includes(selectedFilterOperation);
126126
const defaultOperationSelected = selectedFilterOperation === column.defaultFilterOperation;
127127
const builtInOperationSelected = FILTER_ROW_OPERATIONS.includes(selectedFilterOperation);
128128
const filterValueNotNullOrEmpty = filterValue !== null && filterValue !== '';
@@ -134,11 +134,15 @@ const updateFilterRowCondition = function (columnsController, column, condition)
134134
filterRowOptions = {
135135
filterValue,
136136
selectedFilterOperation,
137+
bufferedFilterValue: undefined,
138+
bufferedSelectedFilterOperation: undefined,
137139
};
138140
} else {
139141
filterRowOptions = {
140142
filterValue: undefined,
141143
selectedFilterOperation: undefined,
144+
bufferedFilterValue: undefined,
145+
bufferedSelectedFilterOperation: undefined,
142146
};
143147
}
144148
columnsController.columnOption(getColumnIdentifier(column), filterRowOptions);
@@ -170,12 +174,11 @@ export class FilterSyncController extends modules.Controller {
170174
}
171175

172176
public syncFilterValue() {
173-
const that = this;
174177
const columns = this._columnsController.getFilteringColumns();
175178

176179
this._skipSyncColumnOptions = true;
177180
columns.forEach((column) => {
178-
const filterConditions = getMatchedConditions(that.option('filterValue'), getColumnIdentifier(column));
181+
const filterConditions = getMatchedConditions(this.option('filterValue'), getColumnIdentifier(column));
179182
if (filterConditions.length === 1) {
180183
const filterCondition = filterConditions[0];
181184
updateHeaderFilterCondition(this._columnsController, column, filterCondition);

0 commit comments

Comments
 (0)