@@ -11,9 +11,14 @@ import { EventEmitterBase } from '../internal/mixins/event-emitter.js';
11
11
import { watch } from '../internal/watch.js' ;
12
12
import { DEFAULT_COLUMN_CONFIG , PIPELINE } from '../internal/constants.js' ;
13
13
import { registerGridIcons } from '../internal/icon-registry.js' ;
14
- import { asArray , getFilterOperandsFor } from '../internal/utils.js' ;
15
-
16
- import type { ColumnConfig , GridRemoteConfig , GridSortingConfig , Keys } from '../internal/types.js' ;
14
+ import { asArray , autoGenerateColumns , getFilterOperandsFor } from '../internal/utils.js' ;
15
+
16
+ import type {
17
+ ColumnConfiguration ,
18
+ GridRemoteConfig ,
19
+ GridSortConfiguration ,
20
+ Keys ,
21
+ } from '../internal/types.js' ;
17
22
import type { FilterExpressionTree } from '../operations/filter/tree.js' ;
18
23
import type { FilterExpression } from '../operations/filter/types.js' ;
19
24
import type { SortExpression } from '../operations/sort/types.js' ;
@@ -49,18 +54,76 @@ defineComponents(
49
54
IgcDropdownItemComponent ,
50
55
) ;
51
56
57
+ /**
58
+ * Event object for the filtering event of the grid.
59
+ */
52
60
export interface ApexFilteringEvent < T extends object > {
61
+ /**
62
+ * The filter expression to apply.
63
+ */
53
64
expression : FilterExpression < T > ;
65
+ /**
66
+ * The filter state of the column.
67
+ */
54
68
state : FilterExpressionTree < T > ;
55
69
}
56
70
57
71
// TODO: Subject to change as these are way too generic names
72
+ /**
73
+ * Events for the apex-grid.
74
+ */
58
75
export interface ApexGridEventMap < T extends object > {
76
+ /**
77
+ * Emitted when sorting is initiated through the UI.
78
+ * Returns the sort expression which will be used for the operation.
79
+ *
80
+ * @remarks
81
+ * The event is cancellable which prevents the operation from being applied.
82
+ * The expression can be modified prior to the operation running.
83
+ *
84
+ * @event
85
+ */
59
86
sorting : CustomEvent < SortExpression < T > > ;
87
+ /**
88
+ * Emitted when a sort operation initiated through the UI has completed.
89
+ * Returns the sort expression used for the operation.
90
+ *
91
+ * @event
92
+ */
60
93
sorted : CustomEvent < SortExpression < T > > ;
94
+ /**
95
+ * Emitted when filtering is initiated through the UI.
96
+ *
97
+ * @remarks
98
+ * The event is cancellable which prevents the operation from being applied.
99
+ * The expression can be modified prior to the operation running.
100
+ *
101
+ * @event
102
+ */
61
103
filtering : CustomEvent < ApexFilteringEvent < T > > ;
104
+ /**
105
+ * Emitted when a filter operation initiated through the UI has completed.
106
+ * Returns the filter state for the affected column.
107
+ *
108
+ * @event
109
+ */
62
110
filtered : CustomEvent < FilterExpressionTree < T > > ;
63
111
}
112
+
113
+ /**
114
+ * Apex grid is a web component for displaying data in a tabular format quick and easy.
115
+ *
116
+ * Out of the box it provides row virtualization, sort and filter operations (client and server side),
117
+ * the ability to template cells and headers and column hiding.
118
+ *
119
+ * @element apex-grid
120
+ *
121
+ * @fires sorting - Emitted when sorting is initiated through the UI.
122
+ * @fires sorted - Emitted when a sort operation initiated through the UI has completed.
123
+ * @fires filtering - Emitted when filtering is initiated through the UI.
124
+ * @fires filtered - Emitted when a filter operation initiated through the UI has completed.
125
+ *
126
+ */
64
127
@themes ( {
65
128
bootstrap,
66
129
fluent,
@@ -107,31 +170,78 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
107
170
@queryAll ( ApexGridRow . is )
108
171
protected _rows ! : NodeListOf < ApexGridRow < T > > ;
109
172
173
+ /** Column configuration for the grid. */
110
174
@property ( { attribute : false } )
111
- public columns : Array < ColumnConfig < T > > = [ ] ;
175
+ public columns : Array < ColumnConfiguration < T > > = [ ] ;
112
176
177
+ /** The data source for the grid. */
113
178
@property ( { attribute : false } )
114
179
public data : Array < T > = [ ] ;
115
180
181
+ /**
182
+ * Whether the grid will try to "resolve" its column configuration based on the passed
183
+ * data source.
184
+ *
185
+ * @remarks
186
+ * This is a one-time operation which is executed when the grid is initially added to the DOM.
187
+ * Passing an empty data source or having a late bound data source (such as a HTTP request) will usually
188
+ * result in empty column configuration for the grid.
189
+ *
190
+ * This property is ignored if any existing column configuration already exists in the grid.
191
+ */
192
+ @property ( { type : Boolean , attribute : 'auto-generate' } )
193
+ public autoGenerate = false ;
194
+
195
+ /** Sort configuration property for the grid. */
116
196
@property ( { attribute : false } )
117
- public sortingConfig : GridSortingConfig = {
197
+ public sortConfiguration : GridSortConfiguration = {
118
198
multiple : true ,
119
199
triState : true ,
120
200
} ;
121
201
202
+ /**
203
+ * Configuration object which controls remote data operations for the grid.
204
+ */
122
205
@property ( { attribute : false } )
123
- public remoteConfig ?: GridRemoteConfig < T > ;
124
-
206
+ public remoteConfiguration ?: GridRemoteConfig < T > ;
207
+
208
+ /**
209
+ * Set sort state for the apex grid.
210
+ *
211
+ * @remarks
212
+ *
213
+ */
125
214
@property ( { attribute : false } )
126
215
public sortExpressions : SortExpression < T > [ ] = [ ] ;
127
216
217
+ /**
218
+ * Set filter state for the apex grid.
219
+ */
128
220
@property ( { attribute : false } )
129
221
public filterExpressions : FilterExpression < T > [ ] = [ ] ;
130
222
223
+ /**
224
+ * Returns the collection of rendered row elements in the grid.
225
+ *
226
+ * @remarks
227
+ * Since the grid has virtualization, this property returns only the currently rendered
228
+ * chunk of elements in the DOM.
229
+ */
131
230
public get rows ( ) {
132
231
return Array . from ( this . _rows ) ;
133
232
}
134
233
234
+ /**
235
+ * Returns the state of the data source after sort/filter operations
236
+ * have been applied.
237
+ */
238
+ public get dataView ( ) : ReadonlyArray < T > {
239
+ return this . dataState ;
240
+ }
241
+
242
+ /**
243
+ * The total number of items in the {@link ApexGrid.dataView} collection.
244
+ */
135
245
public get totalItems ( ) {
136
246
return this . dataState . length ;
137
247
}
@@ -141,6 +251,11 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
141
251
registerGridIcons ( ) ;
142
252
}
143
253
254
+ public override connectedCallback ( ) {
255
+ super . connectedCallback ( ) ;
256
+ autoGenerateColumns ( this ) ;
257
+ }
258
+
144
259
public override requestUpdate (
145
260
name ?: PropertyKey ,
146
261
oldValue ?: unknown ,
@@ -166,7 +281,7 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
166
281
}
167
282
168
283
@watch ( 'columns' )
169
- protected watchColumns ( _ : ColumnConfig < T > [ ] , newConfig : ColumnConfig < T > [ ] = [ ] ) {
284
+ protected watchColumns ( _ : ColumnConfiguration < T > [ ] , newConfig : ColumnConfiguration < T > [ ] = [ ] ) {
170
285
this . columns = newConfig . map ( config => ( { ...DEFAULT_COLUMN_CONFIG , ...config } ) ) ;
171
286
}
172
287
@@ -186,6 +301,9 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
186
301
) ;
187
302
}
188
303
304
+ /**
305
+ * Performs a filter operation in the grid based on the passed expression(s).
306
+ */
189
307
public filter ( config : FilterExpression < T > | FilterExpression < T > [ ] ) {
190
308
this . stateController . filtering . filter (
191
309
asArray ( config ) . map ( each =>
@@ -198,17 +316,26 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
198
316
) ;
199
317
}
200
318
201
- public sort ( expressions : Partial < SortExpression < T > > | Partial < SortExpression < T > > [ ] ) {
202
- this . stateController . sorting . sort ( expressions as SortExpression < T > [ ] ) ;
319
+ /**
320
+ * Performs a sort operation in the grid based on the passed expression(s).
321
+ */
322
+ public sort ( expressions : SortExpression < T > | SortExpression < T > [ ] ) {
323
+ this . stateController . sorting . sort ( expressions ) ;
203
324
}
204
325
326
+ /**
327
+ * Returns a {@link ColumnConfiguration} for a given column.
328
+ */
205
329
public getColumn ( id : Keys < T > | number ) {
206
330
return typeof id === 'number'
207
331
? this . columns . at ( id )
208
332
: this . columns . find ( ( { key } ) => key === id ) ;
209
333
}
210
334
211
- public updateColumn ( key : Keys < T > , config : Partial < ColumnConfig < T > > ) {
335
+ /**
336
+ * Updates the column configuration of the grid.
337
+ */
338
+ public updateColumn ( key : Keys < T > , config : Partial < ColumnConfiguration < T > > ) {
212
339
// Check and reset data operation states
213
340
// TODO: Run `pipeline` updates ?
214
341
if ( ! config . sort ) {
0 commit comments