Skip to content

Commit 959cd87

Browse files
hanastasovzdrawku
andauthored
Implement and expose a public CellType interface and API (#9853)
* chore(*): add cell API dev sample * feat(grid): implement public CellType interface * feat(grid): expose CellType interface to public API * chore(*): fix dev sample to use public CellType * chore(*): fix code indentation * chore(*): fix code indentation * chore(*): fix code indentation and lint errors * chore(*): fix code indentation * chore(*): fix code indentation * feat(grid): implement row.cells, fix bugs * chore(*): sample enhacements * chore(*): fix lint error in code * fix(grid): fix bugs in cell API implementation * chore(*): fix sample issues * chore(*): fix sample issues, treegridFlat data key is number * feat(grid): implement column.cells * feat(grid): implement column.cell * fix(grid): dont return igxHierarchicalGridRow for child grid containers * chore(*): sample update to remove uneeeded line * chore(*): fix lint errors * feat(grid): implement selectedCells * feat(grid): add get_cell_by_index overload * fix(grid): fix typing issues * test(grid): first batch test fixes * chore(*): fix lint error in treegrid * chore(*): fix lint error in treegrid * fix(grid): fix how crudService creatres a cell and row * test(grid): add second btach of tests * fix(grid): check if row exist in current dataView * test(grid): do not create cell in EditMode, if the row is collapsed * chore(*): fix lint errors * test(grid): third batch of fixed tests * fix(grid): consider if row is added row * test(grid): fix grid search test * test(grid): fix row pinning navigation tests * fix(grid): update to be setter too, consider transactions in treeRow.getdata * test(grid): fix few grid and treegrid tests, use cell component * test(grid): fix some tests to use cell component * test(grid): fix hierarchical grid tests * fix(grid): add support for nested props, crud service bug fix * test(grid): complete hgrid tests * test(grid): complete tgrid tests * fix(grid): fix bug in nested props support * test(grid): fix nested props test to use cell component * fix(grid): clear transactions if editing is cancelled * chore(*): fix circular dep, code formatting, etc * chore(*): add migrations for new CellType interface * chore(*): Update changelog and readme files * fix(grid): bind IgxGridCell to let-cell in template * fix(grid): only update cell in crudService, if same cell * chore(*): add todo comment * chore(*): fix lint error, use const * test(grid): increase debounce time for specific test that proved to be Unstable * fix(grid): dont use ?? operator together with ? * fix(grid): dont use ?? operator together with ? * chore(*): fix lint error with quotes * fix(grid): first take rowData, if available * chore(*): Samples improvements Co-authored-by: Zdravko Kolev <[email protected]>
1 parent bd228e8 commit 959cd87

File tree

77 files changed

+3053
-1502
lines changed

Some content is hidden

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

77 files changed

+3053
-1502
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ All notable changes for each version of this project will be documented in this
4242
</igx-grid>
4343
<button igxButton (click)="grid.transactions.undo">Undo</button>
4444
```
45+
- **Breaking changes**
46+
- `IgxGridCellComponent`, `IgxTreeGridCellComponent`, `IgxHierarchicalGridCellComponent` are no longer exposed in the public API. Instead, a new class `IgxGridCell` replaces all of these. It is a facade class which exposes only the public API of the above mentioned. Automatic migration will change these imports with `CellType`, which is the interface implemented by `IgxGridCell`
47+
- **Behavioral changes**
48+
- `getCellByKey`, `getCellByColumn`, `getCellByColumnVisibleIndex`, `row.cells`, `column.cells`, `grid.selectedCells` now return an `IgxGridCell` the `CellType` interface.
49+
- `cell` in `IGridCellEventArgs` is now `CellType`. `IGridCellEventArgs` are emitetd in `cellClick`, `selected`, `contextMenu` and `doubleClick` events.
50+
- `let-cell` property in cell template is now `CellType`.
51+
- `getCellByColumnVisibleIndex` is now deprecated and will be removed in next major version. Use `getCellByKey`, `getCellByColumn` instead.
4552

4653
- `Transactions`
4754
- Added `IgxFlatTransactionFactory` - the singleton service instantiates a new `TransactionService<Transaction, State>` given a `transaction type`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "../../common/schema/class.schema.json",
3+
"changes": [{
4+
"name": "IgxHierarchicalGridCellComponent",
5+
"replaceWith": "CellType"
6+
},
7+
{
8+
"name": "IgxGridCellComponent",
9+
"replaceWith": "CellType"
10+
},
11+
{
12+
"name": "IgxTreeGridCellComponent",
13+
"replaceWith": "CellType"
14+
},
15+
{
16+
"name": "IgxGridExpandableCellComponent",
17+
"replaceWith": "CellType"
18+
}
19+
]
20+
}

projects/igniteui-angular/migrations/update-12_1_0/index.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,53 @@ public onBannerOpened(event: BannerEventArgs) {
652652
</igx-dialog>`);
653653
});
654654

655+
// CellType
656+
it('Should update cell component types with CellType', async () => {
657+
appTree.create(
658+
'/testSrc/appPrefix/component/cells.component.ts', `
659+
import { IgxGridComponent, IgxGridCellComponent, IgxHierarchicalGridCellComponent,
660+
IgxTreeGridCellComponent, IgxGridExpandableCellComponent } from 'igniteui-angular';
661+
export class HGridMultiRowDragComponent {
662+
public onDropAllowed(args: IDropDroppedEventArgs)
663+
const hierRow: RowType = args.dragData;
664+
const row: RowType = args.dragData;
665+
const treeRow: RowType = args.dragData;
666+
const cells: IgxGridCellComponent[] = row.cells;
667+
const tells: IgxTreeGridCellComponent[] = treeRow.cells;
668+
const hcells: IgxHierarchicalGridCellComponent[] = hierRow.cells;
669+
}
670+
public ngOnInit() {
671+
const cell: this.grid1.getCellByColumn(0, "ContactName") as IgxGridCellComponent;
672+
const cell2: this.grid1.getCellByColumnVisibleIndex(0, 2) as IgxTreeGridCellComponent;
673+
const cell3: this.grid1.getCellByKey(0, "Age") as IgxHierarchicalGridCellComponent;
674+
675+
const cells = grid.selectedCells as IgxGridCellComponent[];
676+
}
677+
}`);
678+
const tree = await schematicRunner.runSchematicAsync(migrationName, {}, appTree)
679+
.toPromise();
680+
681+
expect(tree.readContent('/testSrc/appPrefix/component/cells.component.ts'))
682+
.toEqual(`
683+
import { IgxGridComponent, CellType } from 'igniteui-angular';
684+
export class HGridMultiRowDragComponent {
685+
public onDropAllowed(args: IDropDroppedEventArgs)
686+
const hierRow: RowType = args.dragData;
687+
const row: RowType = args.dragData;
688+
const treeRow: RowType = args.dragData;
689+
const cells: CellType[] = row.cells;
690+
const tells: CellType[] = treeRow.cells;
691+
const hcells: CellType[] = hierRow.cells;
692+
}
693+
public ngOnInit() {
694+
const cell: this.grid1.getCellByColumn(0, "ContactName") as CellType;
695+
const cell2: this.grid1.getCellByColumnVisibleIndex(0, 2) as CellType;
696+
const cell3: this.grid1.getCellByKey(0, "Age") as CellType;
697+
698+
const cells = grid.selectedCells as CellType[];
699+
}
700+
}`);
701+
});
655702
});
656703

657704

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -495,20 +495,23 @@ import {
495495
|--- |--- |--- |
496496
|`toggle()`|void| Toggles the expand state of the group row. |
497497

498-
## IgxGridCellComponent
498+
## IgxGridCell
499499

500500
### Getters/Setters
501501

502502
|Name|Type|Getter|Setter|Description|
503503
|--- |--- |--- |--- |--- |
504-
|`column`|IgxColumnComponent|Yes|No|The column to which the cell belongs.|
505-
|`row`|IgxGridRowComponent|Yes|No|The row to which the cell belongs.|
506-
|`value`|any|Yes|No|The value in the cell.|
507-
|`rowIndex`|number|Yes|No|The index of the row this cell belongs to.|
508-
|`columnIndex`|number|Yes|No|The index of the column this cell belongs to.|
509504
|`grid`|IgxGridComponent|Yes|No|The grid component itself.|
510-
|`inEditMode`|boolean|Yes|Yes|Gets/Sets the cell in edit mode.|
511-
|`nativeElement`|HTMLElement|Yes|No|The native DOM element representing the cell. Could be `null` in certain environments.|
505+
|`column`|IgxColumnComponent|Yes|No|The column to which the cell belongs.|
506+
|`row`|RowType|Yes|No|The row to which the cell belongs.|
507+
|`value`|any|Yes|Yes|The value in the cell.|
508+
|`editValue`|any|Yes|No|The value in the cell editor.|
509+
|`selected`|boolean|Yes|Yes|Returns if the cell is selected.|
510+
|`active`|boolean|Yes|No|Returns if the cell is active (focused).|
511+
|`editable`|boolean|Yes|No|Returns if the cell can enter edit mode).|
512+
|`editMode`|boolean|Yes|Yes|Gets/Sets the cell in edit mode.|
513+
|`cellID`|object|Yes|No|An object describing the cell with `rowID`, `columnID` and `rowIndex`.|
514+
|`editMode`|boolean|Yes|Yes|Gets/Sets the cell in edit mode.|
512515

513516
### Methods
514517

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@angular/core';
22
import { Subject } from 'rxjs';
3-
import { cloneArray, isEqual, reverseMapper, mergeObjects } from '../core/utils';
3+
import { cloneArray, reverseMapper, mergeObjects } from '../core/utils';
44
import { DataUtil, GridColumnDataType } from '../data-operations/data-util';
55
import { ISortingExpression, SortingDirection } from '../data-operations/sorting-expression.interface';
66
import { IgxGridCellComponent } from './cell.component';
@@ -103,11 +103,16 @@ export class GridBaseAPIService<T extends IgxGridBaseDirective & GridType> {
103103
}
104104
}
105105

106-
public get_cell_by_index(rowIndex: number, columnIndex: number): IgxGridCellComponent {
106+
public get_cell_by_index(rowIndex: number, columnID: number | string): IgxGridCellComponent {
107107
const row = this.get_row_by_index(rowIndex);
108-
if (row && row.cells) {
109-
return row.cells.find((cell) => cell.columnIndex === columnIndex);
108+
const hasCells = row && row.cells;
109+
if (hasCells && typeof columnID === 'number') {
110+
return row.cells.find((cell) => cell.column.index === columnID);
111+
}
112+
if (hasCells && typeof columnID === 'string'){
113+
return row.cells.find((cell) => cell.column.field === columnID);
110114
}
115+
111116
}
112117

113118
public get_cell_by_visible_index(rowIndex: number, columnIndex: number): IgxGridCellComponent {

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import { ColumnType } from './common/column.interface';
2525
import { RowType } from './common/row.interface';
2626
import { GridSelectionMode } from './common/enums';
2727
import { GridType } from './common/grid.interface';
28-
import { ISearchInfo } from './grid/public_api';
2928
import { getCurrencySymbol, getLocaleCurrencyCode} from '@angular/common';
3029
import { GridColumnDataType } from '../data-operations/data-util';
3130
import { IgxRowDirective } from './row.directive';
31+
import { ISearchInfo } from './common/events';
32+
import { CellType } from './common/cell.interface';
33+
import { IgxGridCell } from './grid-public-cell';
3234

3335
/**
3436
* Providing reference to `IgxGridCellComponent`:
@@ -165,7 +167,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
165167
public get context(): any {
166168
return {
167169
$implicit: this.value,
168-
cell: this,
170+
cell: this.getCellType(),
169171
additionalTemplateContext: this.column.additionalTemplateContext
170172
};
171173
}
@@ -193,9 +195,9 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
193195
}
194196

195197
/**
196-
* Gets the cell template.
198+
* Gets the pinned indicator template.
197199
* ```typescript
198-
* let template = this.cell.template;
200+
* let template = this.cell.pinnedIndicatorTemplate;
199201
* ```
200202
*
201203
* @memberof IgxGridCellComponent
@@ -257,7 +259,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
257259
}
258260

259261
/**
260-
* Gets the visible `index` of the in which the cell is stored.
262+
* Returns the column visible index.
261263
* ```typescript
262264
* let visibleColumnIndex = this.cell.visibleColumnIndex;
263265
* ```
@@ -412,7 +414,6 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
412414
return this.column.gridColumnSpan;
413415
}
414416

415-
416417
public get rowEnd(): number {
417418
return this.column.rowEnd;
418419
}
@@ -678,7 +679,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
678679
}
679680

680681
this.grid.doubleClick.emit({
681-
cell: this,
682+
cell: this.getCellType(),
682683
event
683684
});
684685
};
@@ -690,7 +691,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
690691
@HostListener('click', ['$event'])
691692
public onClick(event: MouseEvent) {
692693
this.grid.cellClick.emit({
693-
cell: this,
694+
cell: this.getCellType(),
694695
event
695696
});
696697
}
@@ -702,7 +703,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
702703
@HostListener('contextmenu', ['$event'])
703704
public onContextMenu(event: MouseEvent) {
704705
this.grid.contextMenu.emit({
705-
cell: this,
706+
cell: this.getCellType(),
706707
event
707708
});
708709
}
@@ -908,7 +909,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
908909
this.selectionService.keyboardStateOnFocus(node, this.grid.rangeSelected, this.nativeElement);
909910
}
910911
if (this.grid.isCellSelectable && shouldEmitSelection) {
911-
this.grid.selected.emit({ cell: this, event });
912+
this.grid.selected.emit({ cell: this.getCellType(), event });
912913
}
913914
}
914915

@@ -1031,4 +1032,8 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
10311032
this.nativeElement.removeEventListener('pointerenter', this.pointerenter);
10321033
this.nativeElement.removeEventListener('pointerup', this.pointerup);
10331034
}
1035+
1036+
private getCellType(): CellType {
1037+
return new IgxGridCell(this.grid, this.row.index, this.column.field);
1038+
}
10341039
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
} from '@angular/core';
1313

1414
import { IgxColumnComponent } from './column.component';
15-
import { IgxGridCellComponent } from '../cell.component';
1615
import { flatten } from '../../core/utils';
16+
import { CellType } from '../common/cell.interface';
1717

1818

1919
@Component({
@@ -189,14 +189,14 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
189189
*/
190190
public set inlineEditorTemplate(template: TemplateRef<any>) { }
191191
/**
192-
* Gets the column group cells.
192+
* Will return empty array. Use this.children.toArray()[index].cells to get the cells for a column that is part of the column group.
193193
* ```typescript
194194
* let columnCells = this.columnGroup.cells;
195195
* ```
196196
*
197197
* @memberof IgxColumnGroupComponent
198198
*/
199-
public get cells(): IgxGridCellComponent[] {
199+
public get cells(): CellType[] {
200200
return [];
201201
}
202202
/**

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ import { DropPosition } from '../moving/moving.service';
5252
import { IgxColumnGroupComponent } from './column-group.component';
5353
import { IColumnVisibilityChangingEventArgs, IPinColumnCancellableEventArgs, IPinColumnEventArgs } from '../common/events';
5454
import { PlatformUtil } from '../../core/utils';
55+
import { CellType } from '../common/cell.interface';
56+
import { IgxGridCell } from '../grid-public-cell';
5557

5658
const DEFAULT_DATE_FORMAT = 'mediumDate';
5759
const DEFAULT_TIME_FORMAT = 'mediumTime';
@@ -1202,19 +1204,33 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
12021204
/**
12031205
* Gets the cells of the column.
12041206
* ```typescript
1205-
* let columnCells = this.column.cells;
1207+
* let columnCells = this.column._cells;
12061208
* ```
12071209
*
1208-
* @memberof IgxColumnComponent
12091210
*/
1210-
public get cells(): IgxGridCellComponent[] {
1211+
public get cells(): CellType[] {
1212+
return this.grid.dataView
1213+
.map((rec, index) => {
1214+
if (!this.grid.isGroupByRecord(rec) && !this.grid.isSummaryRow(rec)) {
1215+
const cell = new IgxGridCell(this.grid as any, index, this.field);
1216+
return cell;
1217+
}
1218+
}).filter(cell => cell);
1219+
}
1220+
1221+
1222+
/**
1223+
* @hidden @internal
1224+
*/
1225+
public get _cells(): IgxGridCellComponent[] {
12111226
return this.grid.rowList.filter((row) => row instanceof IgxRowDirective)
12121227
.map((row) => {
1213-
if (row.cells) {
1214-
return row.cells.filter((cell) => cell.columnIndex === this.index);
1228+
if (row._cells) {
1229+
return row._cells.filter((cell) => cell.columnIndex === this.index);
12151230
}
12161231
}).reduce((a, b) => a.concat(b), []);
12171232
}
1233+
12181234
/**
12191235
* Gets the column visible index.
12201236
* If the column is not visible, returns `-1`.
@@ -2247,12 +2263,12 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
22472263
const range = this.grid.document.createRange();
22482264
const largest = new Map<number, number>();
22492265

2250-
if (this.cells.length > 0) {
2266+
if (this._cells.length > 0) {
22512267
const cellsContentWidths = [];
2252-
this.cells.forEach((cell) => cellsContentWidths.push(cell.calculateSizeToFit(range)));
2268+
this._cells.forEach((cell) => cellsContentWidths.push(cell.calculateSizeToFit(range)));
22532269

22542270
const index = cellsContentWidths.indexOf(Math.max(...cellsContentWidths));
2255-
const cellStyle = this.grid.document.defaultView.getComputedStyle(this.cells[index].nativeElement);
2271+
const cellStyle = this.grid.document.defaultView.getComputedStyle(this._cells[index].nativeElement);
22562272
const cellPadding = parseFloat(cellStyle.paddingLeft) + parseFloat(cellStyle.paddingRight) +
22572273
parseFloat(cellStyle.borderLeftWidth) + parseFloat(cellStyle.borderRightWidth);
22582274

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { IgxColumnComponent } from '../columns/column.component';
2+
import { IgxGridComponent } from '../grid/grid.component';
3+
import { IgxHierarchicalGridComponent } from '../hierarchical-grid/hierarchical-grid.component';
4+
import { IgxTreeGridComponent } from '../tree-grid/tree-grid.component';
5+
import { RowType } from './row.interface';
6+
7+
export interface CellType {
8+
value: any;
9+
editValue: any;
10+
selected: boolean;
11+
active: boolean;
12+
editable: boolean;
13+
editMode: boolean;
14+
column: IgxColumnComponent;
15+
row: RowType;
16+
grid: IgxGridComponent | IgxTreeGridComponent | IgxHierarchicalGridComponent;
17+
cellID: { rowID: any; columnID: number; rowIndex: number };
18+
width: string;
19+
update: (value: any) => void;
20+
}
21+

projects/igniteui-angular/src/lib/grids/common/column.interface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export interface ColumnType {
4444
width: string;
4545
topLevelParent?: ColumnType;
4646
parent?: ColumnType;
47-
hasLastPinnedChildColumn: boolean;
4847
pipeArgs: IColumnPipeArgs;
4948
hasNestedPath: boolean;
5049
defaultTimeFormat: string;

0 commit comments

Comments
 (0)