Skip to content

Commit c1bcb39

Browse files
authored
DataGrid(T1267471): ColumnChooser doesn't immediately reflect the changes made to column options (DevExpress#30851)
1 parent facc0ba commit c1bcb39

File tree

3 files changed

+83
-13
lines changed

3 files changed

+83
-13
lines changed

e2e/testcafe-devextreme/tests/dataGrid/common/columnChooser.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,48 @@ test('Check the behavior of pressing the Esc button when dragging a column from
192192
mode: 'dragAndDrop',
193193
},
194194
}));
195+
196+
test(
197+
'Should take into account column options change during general option change (T1267471)',
198+
async (t) => {
199+
const dataGrid = new DataGrid('#container');
200+
const columnChooserBtn = dataGrid.getColumnChooserButton();
201+
202+
await t.click(columnChooserBtn);
203+
204+
const columnChooser = dataGrid.getColumnChooser();
205+
const lastItemCheckbox = columnChooser.getCheckbox(1);
206+
207+
await t.expect(columnChooser.isCheckboxDisabled(0)).notOk();
208+
await t.expect(columnChooser.isCheckboxDisabled(1)).notOk();
209+
210+
await t.click(lastItemCheckbox);
211+
212+
await t.expect(columnChooser.isCheckboxDisabled(0)).ok();
213+
await t.expect(columnChooser.isCheckboxDisabled(1)).notOk();
214+
},
215+
).before(async () => createWidget('dxDataGrid', {
216+
dataSource: [
217+
{ id: 0, A: 'A', B: 'B' },
218+
],
219+
keyExpr: 'id',
220+
columns: ['A', 'B'],
221+
columnChooser: {
222+
enabled: true,
223+
mode: 'select',
224+
},
225+
onOptionChanged: ({ component, fullName }) => {
226+
if (!/columns\[\d+\]\.visible/.test(fullName)) {
227+
return;
228+
}
229+
230+
const visibleColumns = component.getVisibleColumns();
231+
const [{ dataField: lastColumnDataField }] = visibleColumns;
232+
233+
if (!lastColumnDataField) {
234+
return;
235+
}
236+
237+
component.columnOption(lastColumnDataField, 'allowHiding', false);
238+
},
239+
}));

packages/devextreme/js/__internal/grids/grid_core/column_chooser/m_column_chooser.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,25 +376,45 @@ export class ColumnChooserView extends ColumnsView {
376376
this._columnChooserList.endUpdate();
377377
}
378378

379-
protected _columnOptionChanged(e) {
380-
super._columnOptionChanged(e);
379+
protected _columnOptionChanged(changes): void {
380+
super._columnOptionChanged(changes);
381381

382+
const { optionNames } = changes;
382383
const isSelectMode = this.isSelectMode();
384+
const onlyVisibleChanged = this.isColumnVisibilityOnlyUpdated(optionNames);
385+
const isOnlyColumnVisibilityUpdated = this._isUpdatingColumnVisibility
386+
&& onlyVisibleChanged;
383387

384-
if (isSelectMode && this._columnChooserList && !this._isUpdatingColumnVisibility) {
385-
const { optionNames } = e;
386-
const onlyVisibleChanged = optionNames.visible && optionNames.length === 1;
387-
const columnIndices = isDefined(e.columnIndex) ? [e.columnIndex] : e.columnIndices;
388-
const needUpdate = COLUMN_OPTIONS_USED_IN_ITEMS.some((optionName) => optionNames[optionName]) || (e.changeTypes.columns && optionNames.all);
388+
if (!isSelectMode || !this._columnChooserList || isOnlyColumnVisibilityUpdated) {
389+
return;
390+
}
389391

390-
if (needUpdate) {
391-
this._updateItemsSelection(columnIndices);
392+
const columnIndices = isDefined(changes.columnIndex)
393+
? [changes.columnIndex]
394+
: changes.columnIndices;
395+
const hasItemsOptionNames = COLUMN_OPTIONS_USED_IN_ITEMS
396+
.some((optionName) => optionNames[optionName]);
397+
const needUpdate: boolean = hasItemsOptionNames
398+
|| (changes.changeTypes.columns && optionNames.all);
392399

393-
if (!onlyVisibleChanged) {
394-
this._updateItems();
395-
}
396-
}
400+
if (!needUpdate) {
401+
return;
397402
}
403+
404+
this._updateItemsSelection(columnIndices);
405+
if (!onlyVisibleChanged) {
406+
this._updateItems();
407+
}
408+
}
409+
410+
private isColumnVisibilityOnlyUpdated(
411+
optionNames: { length: number } & Record<string, unknown>,
412+
): boolean {
413+
const optionKeys = Object
414+
.keys(optionNames ?? {})
415+
.filter((key) => key !== 'length');
416+
417+
return optionKeys.length === 1 && optionKeys[0] === 'visible';
398418
}
399419

400420
public getColumnElements() {

packages/testcafe-models/dataGrid/columnChooser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const CLASS = {
77
overlayWrapper: 'dx-overlay-wrapper',
88
columnChooser: 'dx-datagrid-column-chooser',
99
checkboxChecked: 'dx-checkbox-checked',
10+
checkboxDisabled: 'dx-state-disabled',
1011
checkbox: 'dx-checkbox',
1112
treeViewItem: 'dx-treeview-item',
1213
treeView: 'dx-treeview',
@@ -49,6 +50,10 @@ export default class ColumnChooser extends FocusableElement {
4950
return this.getCheckbox(nth).hasClass(CLASS.checkboxChecked);
5051
}
5152

53+
isCheckboxDisabled(nth = 0): Promise<boolean> {
54+
return this.getCheckbox(nth).hasClass(CLASS.checkboxDisabled);
55+
}
56+
5257
getColumnsCount(): Promise<number> {
5358
return this.content.find(`.${CLASS.treeViewItem}`).count;
5459
}

0 commit comments

Comments
 (0)