Skip to content

Commit 0a4e50e

Browse files
authored
CardView/DataGrid - Selection: Clear selection does not work when change the showCheckBoxesMode option at runtime (#31410)
1 parent 4def9a9 commit 0a4e50e

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

e2e/testcafe-devextreme/tests/cardView/selection/functional.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,32 @@ test('Switching the showCheckBoxesMode option from always to onClick at runtime
968968
showCheckBoxesMode: 'always',
969969
},
970970
}));
971+
972+
test('"Deselect all" should work after changing showCheckboxMode', async (t) => {
973+
const cardView = new CardView('#container');
974+
975+
await cardView.option('selection.showCheckBoxesMode', 'onClick');
976+
977+
await t.click(
978+
cardView.getToolbar().getClearSelectionButton(),
979+
);
980+
981+
await t
982+
.expect(cardView.getToolbar().isClearSelectionButtonDisabled())
983+
.ok();
984+
985+
for (let i = 0; i < 6; i += 1) {
986+
await t
987+
.expect(cardView.getCard(i).isSelected)
988+
.notOk();
989+
}
990+
}).before(async () => createWidget('dxCardView', {
991+
dataSource: [
992+
{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }, { a: 6 },
993+
],
994+
keyExpr: 'a',
995+
selection: {
996+
mode: 'multiple',
997+
},
998+
selectedCardKeys: [1, 2],
999+
}));

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,36 @@ test('"Select All" checkbox should not react when not visible', async (t) => {
294294
width: 90,
295295
}],
296296
}));
297+
298+
test('"Deselect all" should work after changing showCheckboxMode', async (t) => {
299+
const dataGrid = new DataGrid('#container');
300+
301+
await dataGrid.option('selection.showCheckBoxesMode', 'onClick');
302+
303+
const selectAllCheckBox = new CheckBox(
304+
dataGrid.getHeaders().getHeaderRow(0).getHeaderCell(0).getEditor().element,
305+
);
306+
307+
await t.click(selectAllCheckBox.element); // select all
308+
await t.click(selectAllCheckBox.element); // deselect all
309+
310+
await t
311+
.expect(selectAllCheckBox.option('value'))
312+
.eql(false);
313+
314+
for (let i = 0; i < 7; i += 1) {
315+
await t
316+
.expect(dataGrid.getDataRow(i).isSelected)
317+
.notOk();
318+
}
319+
}).before(async () => createWidget('dxDataGrid', {
320+
dataSource: [
321+
{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }, { a: 6 }, { a: 7 },
322+
],
323+
keyExpr: 'a',
324+
selection: {
325+
mode: 'multiple',
326+
showCheckBoxesMode: 'always',
327+
},
328+
selectedRowKeys: [1, 2],
329+
}));

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ export class SelectionController extends modules.Controller {
440440
this.selectRows(selectedRowKeys).always(() => {
441441
this._fireSelectionChanged();
442442
});
443+
} else {
444+
this.refresh().always(() => {
445+
this._fireSelectionChanged();
446+
});
443447
}
444448

445449
this._columnsController.updateColumns();

packages/devextreme/js/__internal/grids/new/grid_core/selection/controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ export class SelectionController {
149149
});
150150

151151
effect(() => {
152+
/*
153+
TODO: subscription to selectionHelper to update keys if it is reinitialized.
154+
Need to get rid of `selectionHelper.peek()` inside of selectCards()
155+
and pass selectionHelper from here
156+
*/
157+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
158+
this.selectionHelper.value;
159+
152160
const isLoaded = this.dataController.isLoaded.value;
153161
if (isLoaded) {
154162
const selectedCardKeys = this.selectedCardKeys.peek();

0 commit comments

Comments
 (0)