Skip to content

Commit 7f15865

Browse files
authored
CardView - Fix selectAll when some filter is applied - T1298718 (DevExpress#30468)
1 parent 58744d1 commit 7f15865

File tree

4 files changed

+127
-8
lines changed

4 files changed

+127
-8
lines changed

packages/devextreme/js/__internal/grids/new/grid_core/filtering/public_methods.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,5 @@ export function PublicMethods<T extends Constructor<GridCoreNewBase>>(GridCore:
99
public clearFilter(): void {
1010
this.filterSyncController.clearFilters();
1111
}
12-
13-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14-
public getCombinedFilter(): any {
15-
return this.filterController.displayFilter.peek();
16-
}
1712
};
1813
}

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

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,128 @@ describe('when keyExpr is missing', () => {
174174
});
175175
});
176176
});
177+
178+
describe('selectAll with filters', () => {
179+
it('should select only cards matching filterValue', () => {
180+
const cardView = setup({
181+
keyExpr: 'id',
182+
columns: ['id', 'category'],
183+
dataSource: [
184+
{ id: 1, category: 'A' },
185+
{ id: 2, category: 'A' },
186+
{ id: 3, category: 'B' },
187+
{ id: 4, category: 'B' },
188+
],
189+
selection: {
190+
mode: 'multiple',
191+
allowSelectAll: true,
192+
},
193+
filterPanel: {
194+
filterEnabled: true,
195+
},
196+
});
197+
198+
cardView.option('filterValue', ['category', '=', 'A']);
199+
cardView.selectAll();
200+
201+
expect(cardView.getSelectedCardKeys()).toEqual([1, 2]);
202+
});
203+
204+
it('should select only cards matching headerFilter', () => {
205+
const cardView = setup({
206+
keyExpr: 'id',
207+
columns: ['id', 'category'],
208+
dataSource: [
209+
{ id: 1, category: 'A' },
210+
{ id: 2, category: 'A' },
211+
{ id: 3, category: 'B' },
212+
{ id: 4, category: 'B' },
213+
],
214+
selection: {
215+
mode: 'multiple',
216+
allowSelectAll: true,
217+
},
218+
filterPanel: {
219+
filterEnabled: true,
220+
},
221+
});
222+
223+
cardView.columnOption('category', 'filterValues', ['A']);
224+
cardView.selectAll();
225+
226+
expect(cardView.getSelectedCardKeys()).toEqual([1, 2]);
227+
});
228+
229+
it('should select only cards matching dataSource.filter()', () => {
230+
const cardView = setup({
231+
keyExpr: 'id',
232+
columns: ['id', 'category'],
233+
dataSource: [
234+
{ id: 1, category: 'A' },
235+
{ id: 2, category: 'A' },
236+
{ id: 3, category: 'B' },
237+
{ id: 4, category: 'B' },
238+
],
239+
selection: {
240+
mode: 'multiple',
241+
allowSelectAll: true,
242+
},
243+
filterPanel: {
244+
filterEnabled: true,
245+
},
246+
});
247+
248+
cardView.getDataSource().filter(['category', '=', 'A']);
249+
cardView.selectAll();
250+
251+
expect(cardView.getSelectedCardKeys()).toEqual([1, 2]);
252+
});
253+
254+
it('should select only cards matching filterValue, headerFilter and dataSource.filter()', () => {
255+
const cardView = setup({
256+
keyExpr: 'id',
257+
columns: ['id', 'category1', 'category2', 'category3'],
258+
dataSource: [
259+
{
260+
id: 1, category1: 'A', category2: '1', category3: true,
261+
},
262+
{
263+
id: 2, category1: 'A', category2: '1', category3: false,
264+
},
265+
{
266+
id: 3, category1: 'A', category2: '2', category3: true,
267+
},
268+
{
269+
id: 4, category1: 'A', category2: '2', category3: false,
270+
},
271+
{
272+
id: 5, category1: 'B', category2: '3', category3: true,
273+
},
274+
{
275+
id: 6, category1: 'B', category2: '3', category3: false,
276+
},
277+
{
278+
id: 7, category1: 'B', category2: '4', category3: true,
279+
},
280+
{
281+
id: 8, category1: 'B', category2: '4', category3: false,
282+
},
283+
],
284+
selection: {
285+
mode: 'multiple',
286+
allowSelectAll: true,
287+
},
288+
filterPanel: {
289+
filterEnabled: true,
290+
},
291+
});
292+
293+
cardView.option('filterValue', ['category1', '=', 'A']);
294+
cardView.columnOption('category2', 'filterValues', ['1']);
295+
cardView.getDataSource().filter(['category3', '=', true]);
296+
297+
cardView.selectAll();
298+
299+
expect(cardView.getSelectedCardKeys()).toEqual([1]);
300+
});
301+
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export class SelectionController {
167167

168168
private getSelectionConfig(dataSource, selectionOption): object {
169169
const selectedCardKeys = this.selectedCardKeys.peek();
170+
const { dataController } = this;
170171

171172
return {
172173
selectedKeys: selectedCardKeys,
@@ -189,8 +190,7 @@ export class SelectionController {
189190
return dataSource.items();
190191
},
191192
filter() {
192-
// TODO Salimov: Need to take combined filter
193-
return dataSource.filter();
193+
return dataController.getCombinedFilter();
194194
},
195195
totalCount: () => dataSource.totalCount(),
196196
onSelectionChanging: this.selectionChanging.bind(this),

packages/testcafe-models/gridCore/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,3 @@ export default abstract class GridCore extends Widget {
153153
)();
154154
}
155155
}
156-

0 commit comments

Comments
 (0)