1
1
import {
2
- ContentChild ,
3
2
ChangeDetectionStrategy ,
4
3
ChangeDetectorRef ,
5
4
Component ,
@@ -8,10 +7,6 @@ import {
8
7
HostBinding ,
9
8
Input ,
10
9
IterableDiffers ,
11
- QueryList ,
12
- TemplateRef ,
13
- ViewChild ,
14
- ViewChildren ,
15
10
ViewContainerRef ,
16
11
Output ,
17
12
EventEmitter ,
@@ -20,9 +15,6 @@ import {
20
15
forwardRef
21
16
} from '@angular/core' ;
22
17
import { IgxSelectionAPIService } from '../../core/selection' ;
23
- import { cloneArray } from '../../core/utils' ;
24
- import { DisplayDensity } from '../../core/displayDensity' ;
25
- import { ISortingExpression } from '../../data-operations/sorting-expression.interface' ;
26
18
import { IgxTreeGridAPIService } from './tree-grid-api.service' ;
27
19
import { IgxGridBaseComponent , IgxGridTransaction } from '../grid-base.component' ;
28
20
import { GridBaseAPIService } from '../api.service' ;
@@ -35,19 +27,19 @@ import { IgxGridNavigationService } from '../grid-navigation.service';
35
27
let NEXT_ID = 0 ;
36
28
37
29
/**
38
- * **Ignite UI for Angular Grid** -
30
+ * **Ignite UI for Angular Tree Grid** -
39
31
* [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/grid.html)
40
32
*
41
- * The Ignite UI Grid is used for presenting and manipulating tabular data in the simplest way possible. Once data
42
- * has been bound, it can be manipulated through filtering, sorting & editing operations .
33
+ * The Ignite UI Tree Grid displays and manipulates hierarchical data with consistent schema formatted as a table and
34
+ * provides features such as sorting, filtering, editing, column pinning, paging, column moving and hiding .
43
35
*
44
36
* Example:
45
37
* ```html
46
- * <igx-grid [data]="employeeData" autoGenerate="false">
38
+ * <igx-tree- grid [data]="employeeData" primaryKey="employeeID" foreignKey="PID " autoGenerate="false">
47
39
* <igx-column field="first" header="First Name"></igx-column>
48
40
* <igx-column field="last" header="Last Name"></igx-column>
49
41
* <igx-column field="role" header="Role"></igx-column>
50
- * </igx-grid>
42
+ * </igx-tree- grid>
51
43
* ```
52
44
*/
53
45
@Component ( {
@@ -64,9 +56,9 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
64
56
/**
65
57
* An @Input property that sets the value of the `id` attribute. If not provided it will be automatically generated.
66
58
* ```html
67
- * <igx-grid [id]="'igx-grid-1'" [data]="Data" [autoGenerate]="true" ></igx-grid>
59
+ * <igx-tree- grid [id]="'igx-tree- grid-1'"></igx-tree -grid>
68
60
* ```
69
- * @memberof IgxGridComponent
61
+ * @memberof IgxTreeGridComponent
70
62
*/
71
63
@HostBinding ( 'attr.id' )
72
64
@Input ( )
@@ -86,45 +78,67 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
86
78
*/
87
79
public flatData : any [ ] ;
88
80
81
+ /**
82
+ * Returns an array of the root level `ITreeGridRecord`s.
83
+ */
89
84
public rootRecords : ITreeGridRecord [ ] ;
90
85
86
+ /**
87
+ * Returns a map of all `ITreeGridRecord`s.
88
+ */
91
89
public records : Map < any , ITreeGridRecord > = new Map < any , ITreeGridRecord > ( ) ;
92
90
91
+ /**
92
+ * Returns an array of processed root `ITreeGridRecord`s.
93
+ */
93
94
public processedRootRecords : ITreeGridRecord [ ] ;
94
95
96
+ /**
97
+ * Returns a map of all processed `ITreeGridRecord`s.
98
+ */
95
99
public processedRecords : Map < any , ITreeGridRecord > = new Map < any , ITreeGridRecord > ( ) ;
96
100
97
101
/**
98
102
* An @Input property that sets the child data key of the `IgxTreeGridComponent`.
99
103
* ```html
100
- * <igx-tree-grid #grid [data]="localData" [showToolbar]="true " [childDataKey]="employees" [autoGenerate]="true"></igx-tree-grid>
104
+ * <igx-tree-grid #grid [data]="employeeData " [childDataKey]="employees" [autoGenerate]="true"></igx-tree-grid>
101
105
* ```
102
- * @memberof IgxTreeGridRowComponent
106
+ * @memberof IgxTreeGridComponent
103
107
*/
104
108
@Input ( )
105
109
public childDataKey ;
106
110
107
111
/**
108
112
* An @Input property that sets the foreign key of the `IgxTreeGridComponent`.
109
113
* ```html
110
- * <igx-tree-grid #grid [data]="localData " [primaryKey]="employeeID" [foreignKey]="parentID" [autoGenerate]="true"></igx-tree-grid>
114
+ * <igx-tree-grid #grid [data]="employeeData " [primaryKey]="employeeID" [foreignKey]="parentID" [autoGenerate]="true"></igx-tree-grid>
111
115
* ```
112
- * @memberof IgxTreeGridRowComponent
116
+ * @memberof IgxTreeGridComponent
113
117
*/
114
118
@Input ( )
115
119
public foreignKey ;
116
120
121
+ /**
122
+ * An @Input property indicating whether child records should be deleted when their parent gets deleted.
123
+ * By default it is set to true and deletes all children along with the parent.
124
+ * ```html
125
+ * <igx-tree-grid [data]="employeeData" [primaryKey]="employeeID" [foreignKey]="parentID" cascadeOnDelete="false" [autoGenerate]="true">
126
+ * </igx-tree-grid>
127
+ * ```
128
+ * @memberof IgxTreeGridComponent
129
+ */
117
130
@Input ( )
118
131
public cascadeOnDelete = true ;
119
132
120
133
private _expansionDepth = Infinity ;
121
134
122
135
/**
123
- * An @Input property that sets the count of levels to expand by default in the `IgxTreeGridComponent`.
136
+ * An @Input property that sets the count of levels to be expanded in the `IgxTreeGridComponent`. By default it is
137
+ * set to `Infinity` which means all levels would be expanded.
124
138
* ```html
125
- * <igx-tree-grid #grid [data]="localData " [childDataKey]="employees" expandedLevels ="1" [autoGenerate]="true"></iigx -tree-grid>
139
+ * <igx-tree-grid #grid [data]="employeeData " [childDataKey]="employees" expansionDepth ="1" [autoGenerate]="true"></igx -tree-grid>
126
140
* ```
127
- * @memberof IgxTreeGridRowComponent
141
+ * @memberof IgxTreeGridComponent
128
142
*/
129
143
@Input ( )
130
144
public get expansionDepth ( ) : number {
@@ -138,6 +152,13 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
138
152
139
153
private _expansionStates : Map < any , boolean > = new Map < any , boolean > ( ) ;
140
154
155
+ /**
156
+ * Returns a list of key-value pairs [row ID, expansion state]. Includes only states that differ from the default one.
157
+ * ```typescript
158
+ * const expansionStates = this.grid.expansionStates;
159
+ * ```
160
+ * @memberof IgxTreeGridComponent
161
+ */
141
162
@Input ( )
142
163
public get expansionStates ( ) {
143
164
return this . _expansionStates ;
@@ -148,6 +169,25 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
148
169
this . cdr . detectChanges ( ) ;
149
170
}
150
171
172
+ /**
173
+ * Emitted when the expanded state of a row gets changed.
174
+ * ```typescript
175
+ * rowToggle(event: IRowToggleEventArgs){
176
+ * // the id of the row
177
+ * const rowID = event.rowID;
178
+ * // the new expansion state
179
+ * const newExpandedState = event.expanded;
180
+ * // the original event that triggered onRowToggle
181
+ * const originalEvent = event.event;
182
+ * // whether the event should be cancelled
183
+ * event.cancel = true;
184
+ * }
185
+ * ```
186
+ * ```html
187
+ * <igx-tree-grid [data]="employeeData" (onRowToggle)="rowToggle($event)" [autoGenerate]="true"></igx-tree-grid>
188
+ * ```
189
+ * @memberof IgxTreeGridComponent
190
+ */
151
191
@Output ( )
152
192
public onRowToggle = new EventEmitter < IRowToggleEventArgs > ( ) ;
153
193
@@ -170,11 +210,12 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
170
210
}
171
211
172
212
/**
173
- * Returns if the `IgxGridComponent` has summarized columns.
213
+ * @hidden
214
+ * Returns if the `IgxTreeGridComponent` has summarized columns.
174
215
* ```typescript
175
216
* const summarizedGrid = this.grid.hasSummarizedColumns;
176
217
* ```
177
- * @memberof IgxGridComponent
218
+ * @memberof IgxTreeGridComponent
178
219
*/
179
220
get hasSummarizedColumns ( ) : boolean {
180
221
return false ;
@@ -191,28 +232,63 @@ export class IgxTreeGridComponent extends IgxGridBaseComponent {
191
232
return mapCloned ;
192
233
}
193
234
235
+ /**
236
+ * Expands the `IgxTreeGridRowComponent` with the specified rowID.
237
+ * @param rowID The identifier of the row to be expanded.
238
+ */
194
239
public expandRow ( rowID : any ) {
195
240
this . _gridAPI . expand_row ( this . id , rowID ) ;
196
241
}
197
242
243
+ /**
244
+ * Collapses the `IgxTreeGridRowComponent` with the specified rowID.
245
+ * @param rowID The identifier of the row to be collapsed.
246
+ */
198
247
public collapseRow ( rowID : any ) {
199
248
this . _gridAPI . collapse_row ( this . id , rowID ) ;
200
249
}
201
250
251
+ /**
252
+ * Toggles the expansion state of the `IgxTreeGridRowComponent` with the specified rowID.
253
+ * @param rowID The identifier of the row to be toggled.
254
+ */
202
255
public toggleRow ( rowID : any ) {
203
256
this . _gridAPI . toggle_row_expansion ( this . id , rowID ) ;
204
257
}
205
258
259
+ /**
260
+ * Expands all rows.
261
+ */
206
262
public expandAll ( ) {
207
263
this . _expansionDepth = Infinity ;
208
264
this . expansionStates = new Map < any , boolean > ( ) ;
209
265
}
210
266
267
+ /**
268
+ * Collapses all rows.
269
+ */
211
270
public collapseAll ( ) {
212
271
this . _expansionDepth = 0 ;
213
272
this . expansionStates = new Map < any , boolean > ( ) ;
214
273
}
215
274
275
+ /**
276
+ * Creates a new `IgxTreeGridRowComponent` with the given data. If a parentRowID is not specified, the newly created
277
+ * row would be added at the root level. Otherwise, it would be added as a child of the row whose primaryKey matches
278
+ * the specified parentRowID. If the parentRowID does not exist, an error would be thrown.
279
+ * ```typescript
280
+ * const record = {
281
+ * ID: this.grid.data[this.grid1.data.length - 1].ID + 1,
282
+ * parentID: null,
283
+ * Name: this.newRecord
284
+ * };
285
+ * this.grid.addRow(record); // Adds a new row at level 0.
286
+ * this.grid.addRow(record, 1); // Adds a new child row to the row with ID=1.
287
+ * ```
288
+ * @param data
289
+ * @param parentRowID
290
+ * @memberof IgxTreeGridComponent
291
+ */
216
292
public addRow ( data : any , parentRowID ?: any ) {
217
293
if ( parentRowID ) {
218
294
const parentRecord = this . records . get ( parentRowID ) ;
0 commit comments