Skip to content

Commit 809f192

Browse files
committed
chore(*): address requested changes and comments
1 parent 9e736b7 commit 809f192

File tree

6 files changed

+63
-51
lines changed

6 files changed

+63
-51
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ All notable changes for each version of this project will be documented in this
88
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
99
- `uniqueColumnValuesStrategy` input is added. This property provides a callback for loading unique column values on demand. If this property is provided, the unique values it generates will be used by the Excel Style Filtering (instead of using the unique values from the data that is bound to the grid).
1010
- `igxExcelStyleLoading` directive is added, which can be used to provide a custom loading template for the Excel Style Filtering. If this property is not provided, a default loading template will be used instead.
11-
- introduced new propoerties `cellSelection` and `rowSelection` which accept GridSelection mode enumeration. Grid selection mode could be none, single or multiple. Also `hideRowSelectors` property is added, which allows you to show and hide row selectors when row selection is enabled.
11+
- introduced new properties `cellSelection` and `rowSelection` which accept GridSelection mode enumeration. Grid selection mode could be none, single or multiple. Also `hideRowSelectors` property is added, which allows you to show and hide row selectors when row selection is enabled.
1212
### General
1313
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
14+
- `isCellSelected` method has been deprecated. Now you can use `selected` property.
15+
- `rowSelectable` property has been deprecated. Now you can use `rowSelection` property to enable row selection and also you can show and hide the row selectors by setting `hideRowSelectors` property to true or false (which is the default value).
1416
- Removed deprecated event `OnFocusChange`
1517
- **Breaking Change** `igxExcelStyleSortingTemplate` directive is renamed to `igxExcelStyleSorting`.
1618
- **Breaking Change** `igxExcelStyleMovingTemplate` directive is renamed to `igxExcelStyleMoving`.
1719
- **Breaking Change** `igxExcelStyleHidingTemplate` directive is renamed to `igxExcelStyleHiding`.
18-
- **Breaking Change** `onRowSelectionChange` event arguments are changed. The `row` property has been removed and the priperties `added`, `removed` and `cancel` are newly added.
20+
- **Breaking Change** `onRowSelectionChange` event arguments are changed. The `row` property has been removed and the properties `added`, `removed` and `cancel` are newly added.
1921
- **Breaking Change** `igxExcelStylePinningTemplate` directive is renamed to `igxExcelStylePinning`.
2022
- `IgxCombo`
2123
- Combo selection is now consistent when `valueKey` is defined. When `valueKey` is specified, selection is based on the value keys of the items. For example:

projects/igniteui-angular/src/lib/core/grid-selection.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export class IgxGridSelectionService {
227227
const ranges = Array.from(this._ranges).map(range => JSON.parse(range));
228228

229229
// No ranges but we have a focused cell -> add it
230-
if (!ranges.length && this.activeElement && this.grid.cellSelection !== 'none') {
230+
if (!ranges.length && this.activeElement && this.grid.isCellSelectable) {
231231
ranges.push(this.generateRange(this.activeElement));
232232
}
233233

@@ -304,7 +304,7 @@ export class IgxGridSelectionService {
304304
}
305305

306306
selected(node: ISelectionNode): boolean {
307-
return (this.isActiveNode(node) && this.grid.cellSelection !== 'none' ) || this.isInMap(node);
307+
return (this.isActiveNode(node) && this.grid.isCellSelectable) || this.isInMap(node);
308308
}
309309

310310
isActiveNode(node: ISelectionNode, mrl = false): boolean {
@@ -372,7 +372,6 @@ export class IgxGridSelectionService {
372372
}
373373

374374
keyboardStateOnFocus(node: ISelectionNode, emitter: EventEmitter<GridSelectionRange>, dom): void {
375-
if (this.grid.cellSelection !== 'multiple') { return; }
376375
const kbState = this.keyboardState;
377376

378377
// Focus triggered by keyboard navigation
@@ -543,17 +542,20 @@ export class IgxGridSelectionService {
543542
selection.addRange(range);
544543
}
545544

546-
getSelectedRows() {
545+
/** Returns array of the selected row id's. */
546+
getSelectedRows(): Array<any> {
547547
return this.rowSelection.size ? Array.from(this.rowSelection.keys()) : [];
548548
}
549549

550-
clearRowSelection(event?) {
550+
/** Clears row selection, if filtering is applied clears only selected rows from filtered data. */
551+
clearRowSelection(event?): void {
551552
const removedRec = this.isFilteringApplied() ?
552553
this.getRowIDs(this.allData).filter(rID => this.isRowSelected(rID)) : this.getSelectedRows();
553554
const newSelection = this.isFilteringApplied() ? this.getSelectedRows().filter(x => !removedRec.includes(x)) : [];
554555
this.emitRowSelectionEvent(newSelection, [], removedRec, event);
555556
}
556557

558+
/** Select all rows, if filtering is applied select only from filtered data. */
557559
selectAllRows(event?) {
558560
const allRowIDs = this.getRowIDs(this.allData);
559561
const addedRows = allRowIDs.filter((rID) => !this.isRowSelected(rID));
@@ -562,48 +564,53 @@ export class IgxGridSelectionService {
562564
this.emitRowSelectionEvent(newSelection, addedRows, [], event);
563565
}
564566

565-
selectRowbyID(rowID, clearPrevSelection?, event?) {
566-
if (this.grid.rowSelection === 'none' || this.isRowDeleted(rowID)) { return; }
567-
clearPrevSelection = this.grid.rowSelection === 'single' || clearPrevSelection;
567+
/** Select the specified row and emit event. */
568+
selectRowById(rowID, clearPrevSelection?, event?): void {
569+
if (this.grid.isRowSelectable || this.isRowDeleted(rowID)) { return; }
570+
clearPrevSelection = !this.grid.isMultiRowSelectionEnabled || clearPrevSelection;
568571

569572
const newSelection = clearPrevSelection ? [rowID] : this.getSelectedRows().indexOf(rowID) !== -1 ?
570573
this.getSelectedRows() : [...this.getSelectedRows(), rowID];
571574
const removed = clearPrevSelection ? this.getSelectedRows() : [];
572575
this.emitRowSelectionEvent(newSelection, [rowID], removed, event);
573576
}
574577

575-
deselectRow(rowID, event?) {
578+
/** Deselect the specified row and emit event. */
579+
deselectRow(rowID, event?): void {
576580
if (!this.isRowSelected(rowID)) { return; }
577581
const newSelection = this.getSelectedRows().filter(r => r !== rowID);
578582
if (this.rowSelection.size && this.rowSelection.has(rowID)) {
579583
this.emitRowSelectionEvent(newSelection, [], [rowID], event);
580584
}
581585
}
582586

583-
selectRowsWithNoEvent(rowIDs: any[], clearPrevSelection?) {
587+
/** Select specified rows. No event is emitted. */
588+
selectRowsWithNoEvent(rowIDs: any[], clearPrevSelection?): void {
584589
if (clearPrevSelection) { this.rowSelection.clear(); }
585590
rowIDs.forEach(rowID => { this.rowSelection.add(rowID); });
586591
this.allRowsSelected = undefined;
587592
}
588593

589-
deselectRowsWithNoEvent(rowIDs: any[]) {
594+
/** Deselect specified rows. No event is emitted. */
595+
deselectRowsWithNoEvent(rowIDs: any[]): void {
590596
rowIDs.forEach(rowID => this.rowSelection.delete(rowID));
591597
this.allRowsSelected = undefined;
592598
}
593599

594-
isRowSelected(rowID) {
600+
isRowSelected(rowID): boolean {
595601
return this.rowSelection.size > 0 && this.rowSelection.has(rowID);
596602
}
597603

598-
selectMultipleRows(rowID, rowData, event?) {
604+
/** Select range from last selected row to the current specified row.*/
605+
selectMultipleRows(rowID, rowData, event?): void {
599606
this.allRowsSelected = undefined;
600607
if (!this.rowSelection.size || this.isRowDeleted(rowID)) {
601-
this.selectRowbyID(rowID);
608+
this.selectRowById(rowID);
602609
return;
603610
}
604611
const gridData = this.allData;
605612
const lastRowID = this.getSelectedRows()[this.rowSelection.size - 1];
606-
const currIndex = gridData.indexOf(this.getRowDataByID(lastRowID));
613+
const currIndex = gridData.indexOf(this.getRowDataById(lastRowID));
607614
const newIndex = gridData.indexOf(rowData);
608615
const rows = gridData.slice(Math.min(currIndex, newIndex), Math.max(currIndex, newIndex) + 1);
609616

@@ -613,7 +620,7 @@ export class IgxGridSelectionService {
613620
this.emitRowSelectionEvent(newSelection, added, [], event);
614621
}
615622

616-
areAllRowSelected() {
623+
areAllRowSelected(): boolean {
617624
if (!this.grid.data) { return false; }
618625
if (this.allRowsSelected !== undefined) { return this.allRowsSelected; }
619626

@@ -622,15 +629,15 @@ export class IgxGridSelectionService {
622629
new Set(Array.from(this.rowSelection.values()).concat(dataItemsID)).size === this.rowSelection.size;
623630
}
624631

625-
hasSomeRowSelected() {
632+
hasSomeRowSelected(): boolean {
626633
const filteredData = this.isFilteringApplied() ?
627634
this.getRowIDs(this.grid.filteredData).some(rID => this.isRowSelected(rID)) : true;
628635
return this.rowSelection.size > 0 && filteredData && !this.areAllRowSelected();
629636
}
630637

631638
public emitRowSelectionEvent(newSelection, added, removed, event?): boolean {
632639
const currSelection = this.getSelectedRows();
633-
if (this.areEquelCollections(currSelection, newSelection)) { return; }
640+
if (this.areEqualCollections(currSelection, newSelection)) { return; }
634641

635642
const args = {
636643
oldSelection: currSelection, newSelection: newSelection,
@@ -644,35 +651,36 @@ export class IgxGridSelectionService {
644651
this.selectRowsWithNoEvent(args.newSelection, true);
645652
}
646653

647-
public getRowDataByID(rowID) {
654+
public getRowDataById(rowID): Object {
648655
if (!this.grid.primaryKey) { return rowID; }
649656
const rowIndex = this.getRowIDs(this.grid.gridAPI.get_all_data(true)).indexOf(rowID);
650657
return rowIndex < 0 ? {} : this.grid.gridAPI.get_all_data(true)[rowIndex];
651658
}
652659

653-
public getRowIDs(data) {
660+
public getRowIDs(data): Array<any> {
654661
return this.grid.primaryKey && data.length ? data.map(rec => rec[this.grid.primaryKey]) : data;
655662
}
656663

657-
public clearHeaderCBState() {
664+
public clearHeaderCBState(): void {
658665
this.allRowsSelected = undefined;
659666
}
660667

661-
public get allData() {
668+
/** Returns all data in the grid, with applied filtering and sorting and without deleted rows. */
669+
public get allData(): Array<any> {
662670
const allData = this.isFilteringApplied() || this.grid.sortingExpressions.length ?
663671
this.grid.filteredSortedData : this.grid.gridAPI.get_all_data(true);
664672
return allData.filter(rData => !this.isRowDeleted(this.grid.gridAPI.get_row_id(rData)));
665673
}
666674

667-
private areEquelCollections(first, second) {
668-
return first.length !== second.length || new Set(first.concat(second)).size !== first.length ? false : true;
675+
private areEqualCollections(first, second): boolean {
676+
return first.length === second.length && new Set(first.concat(second)).size === first.length;
669677
}
670678

671-
private isFilteringApplied() {
679+
private isFilteringApplied(): boolean {
672680
return this.grid.filteringExpressionsTree.filteringOperands.length > 0;
673681
}
674682

675-
private isRowDeleted(rowID) {
683+
private isRowDeleted(rowID): boolean {
676684
return this.grid.gridAPI.row_deleted_transaction(rowID);
677685
}
678686
}

projects/igniteui-angular/src/lib/grids/api.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class GridBaseAPIService <T extends IgxGridBaseComponent & IGridDataBinda
152152
if (this.grid.primaryKey === cell.column.field) {
153153
if (this.grid.selectionService.isRowSelected(cell.id.rowID)) {
154154
this.grid.selectionService.deselectRow(cell.id.rowID);
155-
this.grid.selectionService.selectRowbyID(args.newValue);
155+
this.grid.selectionService.selectRowById(args.newValue);
156156
}
157157
if (this.grid.hasSummarizedColumns) {
158158
this.grid.summaryService.removeSummaries(cell.id.rowID);
@@ -248,7 +248,7 @@ export class GridBaseAPIService <T extends IgxGridBaseComponent & IGridDataBinda
248248
const newId = grid.primaryKey ? args.newValue[grid.primaryKey] : args.newValue;
249249
if (selected) {
250250
grid.selectionService.deselectRow(row.id);
251-
grid.selectionService.selectRowbyID(newId);
251+
grid.selectionService.selectRowById(newId);
252252
}
253253
if (hasSummarized) {
254254
grid.summaryService.removeSummaries(newId);

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { getNodeSizeViaRange, ROW_COLLAPSE_KEYS, ROW_EXPAND_KEYS, SUPPORTED_KEYS
2121
import { State } from '../services/index';
2222
import { IgxGridBaseComponent, IGridDataBindable } from './grid-base.component';
2323
import { IgxGridSelectionService, ISelectionNode, IgxGridCRUDService } from '../core/grid-selection';
24-
import { DeprecateProperty } from '../core/deprecateDecorators';
24+
import { DeprecateProperty, DeprecateMethod } from '../core/deprecateDecorators';
2525
import { GridSelectionMode } from './grid-base.component';
2626
import { HammerGesturesManager } from '../core/touch';
2727

@@ -429,7 +429,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
429429
@HostBinding('attr.aria-selected')
430430
@HostBinding('class.igx-grid__td--selected')
431431
get selected() {
432-
return this.isCellSelected();
432+
return this.selectionService.selected(this.selectionNode);
433433
}
434434

435435
/**
@@ -442,7 +442,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
442442
set selected(val: boolean) {
443443
const node = this.selectionNode;
444444
val ? this.selectionService.add(node) : this.selectionService.remove(node);
445-
this.grid.cdr.markForCheck();
445+
this.grid.notifyChanges();
446446
}
447447

448448
@HostBinding('class.igx-grid__td--edited')
@@ -634,14 +634,15 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
634634
}
635635
}
636636

637-
// should be derprecated???
638637
/**
638+
* @deprecated
639639
* Gets whether the cell is selected.
640640
* ```typescript
641641
* let isCellSelected = thid.cell.isCellSelected();
642642
* ```
643643
* @memberof IgxGridCellComponent
644644
*/
645+
@DeprecateMethod(`'isCellSelected' is deprecated. Use 'selected' property instead.`)
645646
public isCellSelected() {
646647
return this.selectionService.selected(this.selectionNode);
647648
}
@@ -803,7 +804,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
803804
const node = this.selectionNode;
804805
const mrl = this.grid.hasColumnLayouts;
805806

806-
if (this.isCellSelectable && !this.selectionService.isActiveNode(node, mrl)) {
807+
if (this.grid.isCellSelectable && !this.selectionService.isActiveNode(node, mrl)) {
807808
this.grid.onSelection.emit({ cell: this, event });
808809
}
809810

@@ -818,7 +819,9 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
818819
}
819820

820821
this.selectionService.primaryButton = true;
821-
this.selectionService.keyboardStateOnFocus(node, this.grid.onRangeSelection, this.nativeElement);
822+
if (this.cellSelectionMode === GridSelectionMode.multiple) {
823+
this.selectionService.keyboardStateOnFocus(node, this.grid.onRangeSelection, this.nativeElement);
824+
}
822825
}
823826

824827
/**
@@ -971,9 +974,9 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
971974
case ' ':
972975
case 'spacebar':
973976
case 'space':
974-
if (this.grid.rowSelection !== 'none') {
977+
if (this.grid.isRowSelectable) {
975978
this.row.selected ? this.selectionService.deselectRow(this.row.rowID, event) :
976-
this.selectionService.selectRowbyID(this.row.rowID, false, event);
979+
this.selectionService.selectRowById(this.row.rowID, false, event);
977980
}
978981
break;
979982
default:
@@ -1055,8 +1058,4 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
10551058
private isToggleKey(key: string): boolean {
10561059
return ROW_COLLAPSE_KEYS.has(key) || ROW_EXPAND_KEYS.has(key);
10571060
}
1058-
1059-
private get isCellSelectable() {
1060-
return this.cellSelectionMode !== GridSelectionMode.none;
1061-
}
10621061
}

projects/igniteui-angular/src/lib/grids/grid-base.component.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5606,19 +5606,21 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
56065606
return rowData.summaries && (rowData.summaries instanceof Map);
56075607
}
56085608

5609-
/**
5610-
* @hidden
5611-
*/
5609+
/** @hidden */
56125610
public get isMultiRowSelectionEnabled(): boolean {
56135611
return this.rowSelection === GridSelectionMode.multiple;
56145612
}
5615-
/**
5616-
* @hidden
5617-
*/
5613+
5614+
/** @hidden */
56185615
public get isRowSelectable(): boolean {
56195616
return this.rowSelection !== GridSelectionMode.none;
56205617
}
56215618

5619+
/** @hidden */
5620+
public get isCellSelectable() {
5621+
return this.cellSelection !== GridSelectionMode.none;
5622+
}
5623+
56225624
/**
56235625
* @hidden
56245626
*/

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { IgxColumnComponent } from './column.component';
2020
import { TransactionType, State } from '../services';
2121
import { IgxGridBaseComponent, IGridDataBindable } from './grid-base.component';
2222
import { IgxGridSelectionService, IgxGridCRUDService, IgxRow } from '../core/grid-selection';
23+
import { DeprecateProperty } from '../core/deprecateDecorators';
2324

2425
@Component({
2526
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -161,7 +162,7 @@ export class IgxRowComponent<T extends IgxGridBaseComponent & IGridDataBindable>
161162
return false;
162163
}
163164

164-
// TODO: should be deprecated?????
165+
@DeprecateProperty('isSelected property is deprecated. Use selected property instead.')
165166
public get isSelected() {
166167
return this.selectionService.isRowSelected(this.rowID);
167168
}
@@ -281,7 +282,7 @@ export class IgxRowComponent<T extends IgxGridBaseComponent & IGridDataBindable>
281282
this.selectionService.selectMultipleRows(this.rowID, this.rowData, event);
282283
return;
283284
}
284-
this.selectionService.selectRowbyID(this.rowID, !event.ctrlKey, event);
285+
this.selectionService.selectRowById(this.rowID, !event.ctrlKey, event);
285286
}
286287

287288
/**
@@ -294,7 +295,7 @@ export class IgxRowComponent<T extends IgxGridBaseComponent & IGridDataBindable>
294295
return;
295296
}
296297
this.selected ? this.selectionService.deselectRow(this.rowID, event) :
297-
this.selectionService.selectRowbyID(this.rowID, false, event);
298+
this.selectionService.selectRowById(this.rowID, false, event);
298299
}
299300

300301
/**

0 commit comments

Comments
 (0)