Skip to content

Commit 11cc058

Browse files
authored
DataGrid(T1267471): ColumnChooser doesn't immediately reflect the changes made to column options (#30851) (#30855)
1 parent d57b183 commit 11cc058

File tree

3 files changed

+97
-13
lines changed

3 files changed

+97
-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
@@ -184,3 +184,48 @@ test('Check the behavior of pressing the Esc button when dragging a column from
184184
mode: 'dragAndDrop',
185185
},
186186
}));
187+
188+
test(
189+
'Should take into account column options change during general option change (T1267471)',
190+
async (t) => {
191+
const dataGrid = new DataGrid('#container');
192+
const columnChooserBtn = dataGrid.getColumnChooserButton();
193+
194+
await t.click(columnChooserBtn);
195+
196+
const columnChooser = dataGrid.getColumnChooser();
197+
const lastItemCheckbox = columnChooser.getCheckbox(1);
198+
199+
await t.expect(columnChooser.isCheckboxDisabled(0)).notOk();
200+
await t.expect(columnChooser.isCheckboxDisabled(1)).notOk();
201+
202+
await t.click(lastItemCheckbox);
203+
204+
await t.expect(columnChooser.isCheckboxDisabled(0)).ok();
205+
await t.expect(columnChooser.isCheckboxDisabled(1)).notOk();
206+
},
207+
).before(async () => createWidget('dxDataGrid', {
208+
dataSource: [
209+
{ id: 0, A: 'A', B: 'B' },
210+
],
211+
keyExpr: 'id',
212+
columns: ['A', 'B'],
213+
columnChooser: {
214+
enabled: true,
215+
mode: 'select',
216+
},
217+
onOptionChanged: ({ component, fullName }) => {
218+
if (!/columns\[\d+\]\.visible/.test(fullName)) {
219+
return;
220+
}
221+
222+
const visibleColumns = component.getVisibleColumns();
223+
const [{ dataField: lastColumnDataField }] = visibleColumns;
224+
225+
if (!lastColumnDataField) {
226+
return;
227+
}
228+
229+
component.columnOption(lastColumnDataField, 'allowHiding', false);
230+
},
231+
}));

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
@@ -403,25 +403,45 @@ export class ColumnChooserView extends ColumnsView {
403403
this._columnChooserList.endUpdate();
404404
}
405405

406-
protected _columnOptionChanged(e) {
407-
super._columnOptionChanged(e);
406+
protected _columnOptionChanged(changes): void {
407+
super._columnOptionChanged(changes);
408408

409+
const { optionNames } = changes;
409410
const isSelectMode = this.isSelectMode();
411+
const onlyVisibleChanged = this.isColumnVisibilityOnlyUpdated(optionNames);
412+
const isOnlyColumnVisibilityUpdated = this._isUpdatingColumnVisibility
413+
&& onlyVisibleChanged;
410414

411-
if (isSelectMode && this._columnChooserList && !this._isUpdatingColumnVisibility) {
412-
const { optionNames } = e;
413-
const onlyVisibleChanged = optionNames.visible && optionNames.length === 1;
414-
const columnIndices = isDefined(e.columnIndex) ? [e.columnIndex] : e.columnIndices;
415-
const needUpdate = COLUMN_OPTIONS_USED_IN_ITEMS.some((optionName) => optionNames[optionName]) || (e.changeTypes.columns && optionNames.all);
415+
if (!isSelectMode || !this._columnChooserList || isOnlyColumnVisibilityUpdated) {
416+
return;
417+
}
416418

417-
if (needUpdate) {
418-
this._updateItemsSelection(columnIndices);
419+
const columnIndices = isDefined(changes.columnIndex)
420+
? [changes.columnIndex]
421+
: changes.columnIndices;
422+
const hasItemsOptionNames = COLUMN_OPTIONS_USED_IN_ITEMS
423+
.some((optionName) => optionNames[optionName]);
424+
const needUpdate: boolean = hasItemsOptionNames
425+
|| (changes.changeTypes.columns && optionNames.all);
419426

420-
if (!onlyVisibleChanged) {
421-
this._updateItems();
422-
}
423-
}
427+
if (!needUpdate) {
428+
return;
424429
}
430+
431+
this._updateItemsSelection(columnIndices);
432+
if (!onlyVisibleChanged) {
433+
this._updateItems();
434+
}
435+
}
436+
437+
private isColumnVisibilityOnlyUpdated(
438+
optionNames: { length: number } & Record<string, unknown>,
439+
): boolean {
440+
const optionKeys = Object
441+
.keys(optionNames ?? {})
442+
.filter((key) => key !== 'length');
443+
444+
return optionKeys.length === 1 && optionKeys[0] === 'visible';
425445
}
426446

427447
public getColumnElements() {

packages/testcafe-models/dataGrid/columnChooser.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const CLASS = {
66
overlayContent: 'dx-overlay-content',
77
overlayWrapper: 'dx-overlay-wrapper',
88
columnChooser: 'dx-datagrid-column-chooser',
9+
checkboxChecked: 'dx-checkbox-checked',
10+
checkboxDisabled: 'dx-state-disabled',
11+
checkbox: 'dx-checkbox',
912
checkboxIcon: 'dx-checkbox-icon',
1013
treeViewItem: 'dx-treeview-item',
1114
treeView: 'dx-treeview',
@@ -44,6 +47,22 @@ export default class ColumnChooser extends FocusableElement {
4447
return this.content.find(`.${CLASS.checkboxIcon}`).nth(nth);
4548
}
4649

50+
getCheckbox(nth = 0): Selector {
51+
return this.content.find(`.${CLASS.checkbox}`).nth(nth);
52+
}
53+
54+
isCheckboxChecked(nth = 0): Promise<boolean> {
55+
return this.getCheckbox(nth).hasClass(CLASS.checkboxChecked);
56+
}
57+
58+
isCheckboxDisabled(nth = 0): Promise<boolean> {
59+
return this.getCheckbox(nth).hasClass(CLASS.checkboxDisabled);
60+
}
61+
62+
getColumnsCount(): Promise<number> {
63+
return this.content.find(`.${CLASS.treeViewItem}`).count;
64+
}
65+
4766
getColumn(index = 0): Selector {
4867
return this.content.find(`.${CLASS.treeViewItem}`).nth(index);
4968
}

0 commit comments

Comments
 (0)