Skip to content

Commit f68f9c6

Browse files
authored
DataGrid (cherry-pick) - fixed "Select All" checkbox behavior when nothing to select (T1299125) (DevExpress#30731)
Signed-off-by: Dmitry Lavrinovich <[email protected]>
1 parent 5a5a6f0 commit f68f9c6

File tree

2 files changed

+64
-9
lines changed
  • e2e/testcafe-devextreme/tests/dataGrid/common
  • packages/devextreme/js/__internal/grids/grid_core/selection

2 files changed

+64
-9
lines changed

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ test('selectAll state should be correct after unselect item if refresh(true) is
1919

2020
// act
2121
await t.click(firstRowSelectionCheckBox.element);
22-
2322
// assert
2423
await t
2524
.expect(await selectAllCheckBox.option('value')).eql(undefined)
@@ -248,3 +247,50 @@ test('Sensitivity option change should be correctly handled during runtime chang
248247
}));
249248

250249
// ---
250+
251+
test('"Select All" checkbox should not react when not visible', async (t) => {
252+
const dataGrid = new DataGrid('#container');
253+
254+
const selectAllCheckBox = new CheckBox(
255+
dataGrid.getHeaders().getHeaderRow(0).getHeaderCell(0).getEditor().element,
256+
);
257+
const editorCell = dataGrid.getHeaders().getHeaderRow(0).getHeaderCell(0).element;
258+
259+
await t.expect(await selectAllCheckBox.option('visible')).notOk();
260+
261+
await t.click(editorCell);
262+
263+
await t.expect(await selectAllCheckBox.option('visible')).notOk();
264+
}).before(async () => createWidget('dxDataGrid', {
265+
dataSource: [],
266+
keyExpr: 'orderId',
267+
selection: {
268+
mode: 'multiple',
269+
},
270+
paging: {
271+
pageSize: 10,
272+
},
273+
pager: {
274+
visible: true,
275+
},
276+
filterRow: {
277+
visible: true,
278+
},
279+
columns: [{
280+
dataField: 'orderId',
281+
caption: 'Order ID',
282+
width: 90,
283+
},
284+
'city', {
285+
dataField: 'country',
286+
width: 180,
287+
},
288+
'region', {
289+
dataField: 'date',
290+
dataType: 'date',
291+
}, {
292+
dataField: 'amount',
293+
format: 'currency',
294+
width: 90,
295+
}],
296+
}));

packages/devextreme/js/__internal/grids/grid_core/selection/m_selection.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -718,15 +718,22 @@ export const columnHeadersSelectionExtenderMixin = (Base: ModuleType<ColumnHeade
718718
this._selectionController.selectionChanged.add(this._updateSelectAllValue.bind(this));
719719
}
720720

721+
private _isSelectAllCheckBoxVisible() {
722+
const isEmptyData = this._dataController.isEmpty();
723+
const allowSelectAll = this.option('selection.allowSelectAll');
724+
const isSelectAll = this._selectionController.isSelectAll();
725+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
726+
return !isEmptyData && (allowSelectAll || isSelectAll !== false);
727+
}
728+
721729
private _updateSelectAllValue() {
722730
const that = this;
723731
const $element = that.element();
724732
const $editor = $element && $element.find(`.${SELECT_CHECKBOX_CLASS}`);
725733

726-
if ($element && $editor.length && that.option('selection.mode') === 'multiple') {
727-
const selectAllValue = that._selectionController.isSelectAll();
728-
const hasSelection = selectAllValue !== false;
729-
const isVisible = that.option('selection.allowSelectAll') ? !that._dataController.isEmpty() : hasSelection;
734+
if ($element && $editor.length && this.option('selection.mode') === 'multiple') {
735+
const selectAllValue = this._selectionController.isSelectAll();
736+
const isVisible = this._isSelectAllCheckBoxVisible();
730737

731738
$editor.dxCheckBox('instance').option({
732739
visible: isVisible,
@@ -758,8 +765,6 @@ export const columnHeadersSelectionExtenderMixin = (Base: ModuleType<ColumnHeade
758765
protected _createSelectAllCheckboxElement(
759766
column?: Column,
760767
): dxElementWrapper {
761-
const isEmptyData = this._dataController.isEmpty();
762-
763768
const $groupElement = $('<div>')
764769
.addClass(SELECT_CHECKBOX_CLASS);
765770

@@ -770,8 +775,7 @@ export const columnHeadersSelectionExtenderMixin = (Base: ModuleType<ColumnHeade
770775
dataType: 'boolean',
771776
value: this._selectionController.isSelectAll(),
772777
editorOptions: {
773-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
774-
visible: !isEmptyData && (this.option('selection.allowSelectAll') || this._selectionController.isSelectAll() !== false),
778+
visible: this._isSelectAllCheckBoxVisible(),
775779
},
776780
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
777781
tabIndex: this.option('useLegacyKeyboardNavigation') ? -1 : this.option('tabIndex') || 0,
@@ -801,6 +805,11 @@ export const columnHeadersSelectionExtenderMixin = (Base: ModuleType<ColumnHeade
801805
eventsEngine.on($element, clickEventName, this.createAction((e) => {
802806
const { event } = e;
803807

808+
if (!this._isSelectAllCheckBoxVisible()) {
809+
event.preventDefault();
810+
return;
811+
}
812+
804813
if (!$(event.target).closest(`.${SELECT_CHECKBOX_CLASS}`).length) {
805814
// @ts-expect-error
806815
eventsEngine.trigger($(event.currentTarget).children(`.${SELECT_CHECKBOX_CLASS}`), clickEventName);

0 commit comments

Comments
 (0)