Skip to content

Commit ff0f4d7

Browse files
authored
Merge pull request #6831 from IgniteUI/nrobakova/column-selection
Column selection
2 parents b36b75e + 68daeb9 commit ff0f4d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2325
-208
lines changed

CHANGELOG.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes for each version of this project will be documented in this
44

55
## 9.1.0
66

7+
### General
8+
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
9+
- **Behavioral Change** - When a column is sortable sort indicator is always visible. The column is sorted when click on it.
10+
711
### Themes
812
- **Breaking Change** Change the default `$legacy-support` value to false in the `igx-theme` function.
913

@@ -17,14 +21,25 @@ All notable changes for each version of this project will be documented in this
1721
```typescript
1822
public pinningConfiguration: IPinningConfig = { columns: ColumnPinningPosition.End };
1923
```
24+
- Added functionality for column selection.
25+
- `selected` property has been added to the IgxColumnComponent; Allows you to set whether the column is selected.
26+
- `selectable` property has been added to the IgxColumnComponent; Allows you to set whether the column is selectable.
27+
- `onColumnSelectionChange` event is added for the `IgxGrid`. It is emitted when the column selection is changed.
28+
- `excelStyleSelectingTemplate` property is introduced to IgxGrid, which allows you to set a custom template for the selecting a column in the Excel Style Filter.
29+
- `selectedColumns` API method is added for the `IgxGrid`. It allows to get all selected columns.
30+
- `selectColumns` API method is added for the `IgxGrid`. It allows to select columns by passing array of IgxColumnComponent or column fields.
31+
- `deselectColumns` API method is added for the `IgxGrid`. It allows to deselect columns by passing array of IgxColumnComponent or column fields.
32+
- `deselectAllColumns` API method is added for the `IgxGrid`. It allows to deselect all columns.
33+
- `getSelectedColumnsData` API method is added for the `IgxGrid`. It allows to get the selected columns data.
34+
2035
- `IgxCombo`:
2136
- Added `autoFocusSearch` input that allows to manipulate the combo's opening behavior. When the property is `true` (by default), the combo's search input is focused on open. When set to `false`, the focus goes to the combo items container, which can be used to prevent the software keyboard from activating on mobile devices when opening the combo.
2237

2338
### RTL Support
2439
- `igxSlider` have full right-to-left (RTL) support.
2540

2641
## 9.0.1
27-
- **Breaking Changes**
42+
- **Breaking Changes**
2843
- Remove `$base-color` from igx-typography. The igx-typography class now inherits the parent color.
2944

3045
## 9.0.0

projects/igniteui-angular/src/lib/core/i18n/grid-resources.ts

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface IGridResourceStrings {
6969
igx_grid_excel_show?: string;
7070
igx_grid_excel_pin?: string;
7171
igx_grid_excel_unpin?: string;
72+
igx_grid_excel_select?: string;
7273
igx_grid_excel_text_filter?: string;
7374
igx_grid_excel_number_filter?: string;
7475
igx_grid_excel_date_filter?: string;
@@ -162,6 +163,7 @@ export const GridResourceStringsEN: IGridResourceStrings = {
162163
igx_grid_excel_show: 'Show column',
163164
igx_grid_excel_pin: 'Pin column',
164165
igx_grid_excel_unpin: 'Unpin column',
166+
igx_grid_excel_select: 'Select column',
165167
igx_grid_excel_text_filter: 'Text filter',
166168
igx_grid_excel_number_filter: 'Number filter',
167169
igx_grid_excel_date_filter: 'Date filter',

projects/igniteui-angular/src/lib/core/styles/components/grid/_excel-filtering-component.scss

+9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@
8585
@extend %grid-excel-actions__action !optional;
8686
}
8787

88+
@include e(actions-select) {
89+
@extend %grid-excel-actions__action !optional;
90+
}
91+
92+
@include e(actions-selected) {
93+
@extend %grid-excel-actions__action !optional;
94+
@extend %grid-excel-actions--selected !optional;
95+
}
96+
8897
@include e(actions-filter) {
8998
@extend %grid-excel-actions__action !optional;
9099
}

projects/igniteui-angular/src/lib/core/styles/components/grid/_excel-filtering-theme.scss

+6
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@
144144
padding: rem(8px) rem(16px);
145145
}
146146

147+
%grid-excel-actions--selected {
148+
igx-icon {
149+
color: igx-color($palette, 'secondary');
150+
}
151+
}
152+
147153
%grid-excel-move {
148154
margin-bottom: rem(8px);
149155

projects/igniteui-angular/src/lib/core/styles/components/grid/_grid-component.scss

+20
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@
233233
@extend %igx-grid__th--sortable !optional;
234234
}
235235

236+
@include e(th, $m: selectable) {
237+
@extend %igx-grid__th--selectable !optional;
238+
}
239+
236240
@include e(th, $m: filtrable) {
237241
@extend %igx-grid__th--filtrable !optional;
238242
}
@@ -245,6 +249,10 @@
245249
@extend %igx-grid__th--sorted !optional;
246250
}
247251

252+
@include e(th, $m: selected) {
253+
@extend %igx-grid__th--selected !optional;
254+
}
255+
248256
@include e(th, $m: number) {
249257
@extend %grid-cell-number !optional;
250258
}
@@ -301,6 +309,14 @@
301309
@extend %grid-cell--selected !optional;
302310
}
303311

312+
@include e(td, $m: column-selected) {
313+
@extend %grid-cell--column-selected !optional;
314+
}
315+
316+
@include e(td, $mods: (selected, column-selected)) {
317+
@extend %grid-cell--cross-selected !optional;
318+
}
319+
304320
@include e(tr, $mods: (selected, filtered)) {
305321
@extend %grid-row--selected--filtered !optional;
306322
}
@@ -372,6 +388,10 @@
372388
@extend %grid-cell--pinned-selected !optional;
373389
}
374390

391+
@include e(td, $mods: (pinned, column-selected)) {
392+
@extend %grid-cell--pinned--column-selected !optional;
393+
}
394+
375395
@include e(td-text) {
376396
@extend %grid-cell-text !optional;
377397
}

projects/igniteui-angular/src/lib/core/styles/components/grid/_grid-theme.scss

+38-21
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,20 @@
12861286
}
12871287
}
12881288

1289+
%grid-cell--column-selected {
1290+
color: --var($theme, 'row-selected-text-color');
1291+
background: --var($theme, 'row-selected-background');
1292+
1293+
&:hover {
1294+
background: --var($theme, 'row-selected-hover-background');
1295+
color: --var($theme, 'row-selected-text-color');
1296+
}
1297+
}
1298+
1299+
%grid-cell--cross-selected {
1300+
background: --var($theme, 'row-selected-cell-background');
1301+
}
1302+
12891303
%igx-grid__td--edited {
12901304
%grid-cell-text {
12911305
font-style: italic;
@@ -1331,6 +1345,16 @@
13311345
// border-bottom: 0;
13321346
}
13331347

1348+
%grid-cell--pinned--column-selected {
1349+
color: --var($theme, 'row-selected-text-color');
1350+
background: --var($theme, 'row-selected-background');
1351+
1352+
&:hover {
1353+
background: --var($theme, 'row-selected-hover-background');
1354+
color: --var($theme, 'row-selected-text-color');
1355+
}
1356+
}
1357+
13341358
%grid-cell--pinned-last {
13351359
border-#{$right}: map-get($cell-pin, 'style') map-get($cell-pin, 'color') !important;
13361360

@@ -1447,36 +1471,29 @@
14471471
justify-content: normal;
14481472
}
14491473

1474+
%igx-grid__th--selectable {
1475+
color: --var($theme, 'row-selected-text-color');
1476+
background: --var($theme, 'row-selected-background');
1477+
opacity: .7;
1478+
}
1479+
1480+
%igx-grid__th--selected {
1481+
color: --var($theme, 'row-selected-text-color');
1482+
background: --var($theme, 'row-selected-cell-background');
1483+
}
1484+
14501485
%igx-grid__th--sortable {
1451-
&:hover {
1486+
.sort-icon {
14521487
cursor: pointer;
1488+
opacity: .7;
14531489

1454-
%grid-cell-header-title {
1455-
cursor: pointer;
1490+
&:hover {
14561491
opacity: 1;
14571492
}
1458-
1459-
.sort-icon {
1460-
opacity: .7;
1461-
1462-
&:hover {
1463-
opacity: 1;
1464-
}
1465-
}
14661493
}
14671494
}
14681495

14691496
%igx-grid__th--sorted {
1470-
%grid-cell-header-title {
1471-
opacity: 1;
1472-
}
1473-
1474-
&:hover{
1475-
.sort-icon {
1476-
opacity: 1;
1477-
}
1478-
}
1479-
14801497
.sort-icon {
14811498
opacity: 1;
14821499
color: --var($theme, 'sorted-header-icon-color');

projects/igniteui-angular/src/lib/grids/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ A list of the events emitted by the **igx-grid**:
232232
|`onColumnMovingStart`|Emitted when a column moving starts. Returns the moved column object.|
233233
|`onSelection`|Emitted when a cell is selected. Returns the cell object.|
234234
|`onRowSelectionChange`|Emitted when a row selection has changed. Returns array with old and new selected rows' IDs and the target row, if available.|
235+
|`onColumnSelectionChange`|Emitted when a column selection has changed. Returns array with old and new selected column' fields|
235236
|`onColumnInit`|Emitted when the grid columns are initialized. Returns the column object.|
236237
|`onSortingDone`|Emitted when sorting is performed through the UI. Returns the sorting expression.|
237238
|`onFilteringDone`|Emitted when filtering is performed through the UI. Returns the filtering expressions tree of the column for which the filtering was performed.|
@@ -290,6 +291,11 @@ Here is a list of all public methods exposed by **igx-grid**:
290291
|`deselectRows(rowIDs: any[])`|Removes the specified row(s) from the grid's selection in the `selectionAPI`.|
291292
|`selectAllRows()`|Marks all rows as selected in the grid `selectionAPI`.|
292293
|`deselectAllRows()`|Sets the grid's row selection in the `selectionAPI` to `[]`.|
294+
|`selectedColumns()`|Returns array of the currently selected columns|
295+
|`selectColumns(columns: string[] | IgxColumnComponent[], clearCurrentSelection?: boolean)`|Marks the specified columns as selected in the grid `selectionAPI`. `clearCurrentSelection` first empties the grid's selection array.|
296+
|`deselectColumns(columns: string[] | IgxColumnComponent[])`|Removes the specified columns from the grid's selection in the `selectionAPI`.|
297+
|`deselectAllColumns()`|Sets the grid's column selection in the `selectionAPI` to `[]`.|
298+
|`getSelectedColumnsData()`|Gets the the data form current selected columns.|
293299
|`findNext(text: string, caseSensitive?: boolean, exactMatch?: boolean)`|Highlights all occurrences of the specified text and marks the next occurrence as active.|
294300
|`findPrev(text: string, caseSensitive?: boolean, exactMatch?: boolean)`|Highlights all occurrences of the specified text and marks the previous occurrence as active.|
295301
|`clearSearch(text: string, caseSensitive?: boolean)`|Removes all search highlights from the grid.|
@@ -324,6 +330,8 @@ Inputs available on the **IgxGridColumnComponent** to define columns:
324330
|`hidden`|boolean|Visibility of the column|
325331
|`movable`|boolean|Set column to be movable|
326332
|`resizable`|boolean|Set column to be resizable|
333+
|`selectable`|boolean|Set column to be selectable|
334+
|`selected`|boolean|Set column to be selected|
327335
|`width`|string|Columns width|
328336
|`minWidth`|string|Columns minimal width|
329337
|`maxWidth`|string|Columns miximum width|

projects/igniteui-angular/src/lib/grids/cell.component.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,18 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
432432
@Input()
433433
width = '';
434434

435+
@HostBinding('attr.aria-selected')
436+
get ariaSelected() {
437+
return this.selected || this.column.selected || this.row.selected;
438+
}
439+
435440
/**
436441
* Gets whether the cell is selected.
437442
* ```typescript
438443
* let isSelected = this.cell.selected;
439444
* ```
440445
* @memberof IgxGridCellComponent
441446
*/
442-
@HostBinding('attr.aria-selected')
443447
@HostBinding('class.igx-grid__td--selected')
444448
get selected() {
445449
return this.selectionService.selected(this.selectionNode);
@@ -458,6 +462,18 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
458462
this.grid.notifyChanges();
459463
}
460464

465+
/**
466+
* Gets whether the cell column is selected.
467+
* ```typescript
468+
* let isCellColumnSelected = this.cell.columnSelected;
469+
* ```
470+
* @memberof IgxGridCellComponent
471+
*/
472+
@HostBinding('class.igx-grid__td--column-selected')
473+
get columnSelected() {
474+
return this.selectionService.isColumnSelected(this.column.field);
475+
}
476+
461477
@HostBinding('class.igx-grid__td--edited')
462478
get dirty() {
463479
if (this.grid.rowEditable) {

projects/igniteui-angular/src/lib/grids/columns/column-group.component.ts

+60-2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
126126
*/
127127
public set filters(classRef: any) { }
128128

129+
/**
130+
* Returns if the column group is selectable
131+
* ```typescript
132+
* let columnGroupSelectable = this.columnGroup.selectable;
133+
* ```
134+
* @memberof IgxColumnGroupComponent
135+
*/
136+
public get selectable(): boolean {
137+
return this.children && this.children.some(child => child.selectable);
138+
}
139+
140+
public set selectable(value: boolean) {}
141+
129142
/**
130143
* Returns a reference to the body template.
131144
* ```typescript
@@ -206,13 +219,40 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
206219
if (this._hidden || !this.collapsible) {
207220
this.children.forEach(child => child.hidden = this._hidden);
208221
} else {
209-
this.children.forEach(c => {
210-
if (c.visibleWhenCollapsed === undefined) {c.hidden = false; return; }
222+
this.children.forEach(c => {
223+
if (c.visibleWhenCollapsed === undefined) { c.hidden = false; return; }
211224
c.hidden = this.expanded ? c.visibleWhenCollapsed : !c.visibleWhenCollapsed;
212225
});
213226
}
214227
}
215228

229+
/**
230+
* Returns if the column group is selected.
231+
* ```typescript
232+
* let isSelected = this.columnGroup.selected;
233+
* ```
234+
* @memberof IgxColumnGroupComponent
235+
*/
236+
get selected(): boolean {
237+
const selectableChildren = this.allChildren.filter(c => !c.columnGroup && c.selectable && !c.hidden);
238+
return selectableChildren.length > 0 && selectableChildren.every(c => c.selected);
239+
}
240+
241+
/**
242+
* Enables/Disables the column group selection.
243+
* ```html
244+
* <igx-column [selected] = "true"></igx-column>
245+
* ```
246+
* @memberof IgxColumnGroupComponent
247+
*/
248+
set selected(value: boolean) {
249+
if (this.selectable) {
250+
this.children.forEach(c => {
251+
c.selected = value;
252+
});
253+
}
254+
}
255+
216256
/**
217257
*@hidden
218258
*/
@@ -299,6 +339,24 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
299339

300340
set width(val) { }
301341

342+
/**
343+
*@hidden
344+
*/
345+
public get applySelectableClass(): boolean {
346+
return this._applySelectableClass;
347+
}
348+
349+
/**
350+
*@hidden
351+
*/
352+
public set applySelectableClass(value: boolean) {
353+
if (this.selectable) {
354+
this._applySelectableClass = value;
355+
this.children.forEach(c => {
356+
c.applySelectableClass = value;
357+
});
358+
}
359+
}
302360
// constructor(public gridAPI: GridBaseAPIService<IgxGridBaseDirective & IGridDataBindable>, public cdr: ChangeDetectorRef) {
303361
// // D.P. constructor duplication due to es6 compilation, might be obsolete in the future
304362
// super(gridAPI, cdr);

0 commit comments

Comments
 (0)