-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
GridOptions.js
539 lines (489 loc) · 22.9 KB
/
GridOptions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
(function(){
angular.module('ui.grid')
.factory('GridOptions', ['gridUtil','uiGridConstants', function(gridUtil,uiGridConstants) {
/**
* @ngdoc function
* @name ui.grid.class:GridOptions
* @description Default GridOptions class. GridOptions are defined by the application developer and overlaid
* over this object. Setting gridOptions within your controller is the most common method for an application
* developer to configure the behaviour of their ui-grid
*
* @example To define your gridOptions within your controller:
* <pre>$scope.gridOptions = {
* data: $scope.myData,
* columnDefs: [
* { name: 'field1', displayName: 'pretty display name' },
* { name: 'field2', visible: false }
* ]
* };</pre>
*
* You can then use this within your html template, when you define your grid:
* <pre><div ui-grid="gridOptions"></div></pre>
*
* To provide default options for all of the grids within your application, use an angular
* decorator to modify the GridOptions factory.
* <pre>
* app.config(function($provide){
* $provide.decorator('GridOptions',function($delegate){
* var gridOptions;
* gridOptions = angular.copy($delegate);
* gridOptions.initialize = function(options) {
* var initOptions;
* initOptions = $delegate.initialize(options);
* initOptions.enableColumnMenus = false;
* return initOptions;
* };
* return gridOptions;
* });
* });
* </pre>
*/
return {
initialize: function( baseOptions ){
/**
* @ngdoc function
* @name onRegisterApi
* @propertyOf ui.grid.class:GridOptions
* @description A callback that returns the gridApi once the grid is instantiated, which is
* then used to interact with the grid programatically.
*
* Note that the gridApi.core.renderingComplete event is identical to this
* callback, but has the advantage that it can be called from multiple places
* if needed
*
* @example
* <pre>
* $scope.gridOptions.onRegisterApi = function ( gridApi ) {
* $scope.gridApi = gridApi;
* $scope.gridApi.selection.selectAllRows( $scope.gridApi.grid );
* };
* </pre>
*
*/
baseOptions.onRegisterApi = baseOptions.onRegisterApi || angular.noop();
/**
* @ngdoc object
* @name data
* @propertyOf ui.grid.class:GridOptions
* @description (mandatory) Array of data to be rendered into the grid, providing the data source or data binding for
* the grid.
*
* Most commonly the data is an array of objects, where each object has a number of attributes.
* Each attribute automatically becomes a column in your grid. This array could, for example, be sourced from
* an angularJS $resource query request. The array can also contain complex objects, refer the binding tutorial
* for examples of that.
*
* The most flexible usage is to set your data on $scope:
*
* `$scope.data = data;`
*
* And then direct the grid to resolve whatever is in $scope.data:
*
* `$scope.gridOptions.data = 'data';`
*
* This is the most flexible approach as it allows you to replace $scope.data whenever you feel like it without
* getting pointer issues.
*
* Alternatively you can directly set the data array:
*
* `$scope.gridOptions.data = [ ];`
* or
*
* `$http.get('/data/100.json')
* .success(function(data) {
* $scope.myData = data;
* $scope.gridOptions.data = $scope.myData;
* });`
*
* Where you do this, you need to take care in updating the data - you can't just update `$scope.myData` to some other
* array, you need to update $scope.gridOptions.data to point to that new array as well.
*
*/
baseOptions.data = baseOptions.data || [];
/**
* @ngdoc array
* @name columnDefs
* @propertyOf ui.grid.class:GridOptions
* @description Array of columnDef objects. Only required property is name.
* The individual options available in columnDefs are documented in the
* {@link ui.grid.class:GridOptions.columnDef columnDef} section
* </br>_field property can be used in place of name for backwards compatibility with 2.x_
* @example
*
* <pre>var columnDefs = [{name:'field1'}, {name:'field2'}];</pre>
*
*/
baseOptions.columnDefs = baseOptions.columnDefs || [];
/**
* @ngdoc object
* @name ui.grid.class:GridOptions.columnDef
* @description Definition / configuration of an individual column, which would typically be
* one of many column definitions within the gridOptions.columnDefs array
* @example
* <pre>{name:'field1', field: 'field1', filter: { term: 'xxx' }}</pre>
*
*/
/**
* @ngdoc object
* @name enableGridMenu
* @propertyOf ui.grid.class:GridOptions
* @description Takes a boolean that adds a settings icon in the top right of the grid, which floats above
* the column header, when true. The menu by default gives access to show/hide columns, but can be
* customised to show additional actions.
*
* See the {@link #!/tutorial/121_grid_menu Grid Menu tutorial} for more detailed information.
*/
/**
* @ngdoc array
* @name excludeProperties
* @propertyOf ui.grid.class:GridOptions
* @description Array of property names in data to ignore when auto-generating column names. Provides the
* inverse of columnDefs - columnDefs is a list of columns to include, excludeProperties is a list of columns
* to exclude.
*
* If columnDefs is defined, this will be ignored.
*
* Defaults to ['$$hashKey']
*/
baseOptions.excludeProperties = baseOptions.excludeProperties || ['$$hashKey'];
/**
* @ngdoc boolean
* @name enableRowHashing
* @propertyOf ui.grid.class:GridOptions
* @description True by default. When enabled, this setting allows uiGrid to add
* `$$hashKey`-type properties (similar to Angular) to elements in the `data` array. This allows
* the grid to maintain state while vastly speeding up the process of altering `data` by adding/moving/removing rows.
*
* Note that this DOES add properties to your data that you may not want, but they are stripped out when using `angular.toJson()`. IF
* you do not want this at all you can disable this setting but you will take a performance hit if you are using large numbers of rows
* and are altering the data set often.
*/
baseOptions.enableRowHashing = baseOptions.enableRowHashing !== false;
/**
* @ngdoc function
* @name rowIdentity
* @methodOf ui.grid.class:GridOptions
* @description This function is used to get and, if necessary, set the value uniquely identifying this row (i.e. if an identity is not present it will set one).
*
* By default it returns the `$$hashKey` property if it exists. If it doesn't it uses gridUtil.nextUid() to generate one
*/
baseOptions.rowIdentity = baseOptions.rowIdentity || function rowIdentity(row) {
return gridUtil.hashKey(row);
};
/**
* @ngdoc function
* @name getRowIdentity
* @methodOf ui.grid.class:GridOptions
* @description This function returns the identity value uniquely identifying this row, if one is not present it does not set it.
*
* By default it returns the `$$hashKey` property but can be overridden to use any property or set of properties you want.
*/
baseOptions.getRowIdentity = baseOptions.getRowIdentity || function getRowIdentity(row) {
return row.$$hashKey;
};
/**
* @ngdoc property
* @name flatEntityAccess
* @propertyOf ui.grid.class:GridOptions
* @description Set to true if your columns are all related directly to fields in a flat object structure - i.e.
* each of your columns associate directly with a property on each of the entities in your data array.
*
* In that situation we can avoid all the logic associated with complex binding to functions or to properties of sub-objects,
* which can provide a significant speed improvement with large data sets when filtering or sorting.
*
* By default false
*/
baseOptions.flatEntityAccess = baseOptions.flatEntityAccess === true;
/**
* @ngdoc property
* @name showHeader
* @propertyOf ui.grid.class:GridOptions
* @description True by default. When set to false, this setting will replace the
* standard header template with '<div></div>', resulting in no header being shown.
*/
baseOptions.showHeader = typeof(baseOptions.showHeader) !== "undefined" ? baseOptions.showHeader : true;
/* (NOTE): Don't show this in the docs. We only use it internally
* @ngdoc property
* @name headerRowHeight
* @propertyOf ui.grid.class:GridOptions
* @description The height of the header in pixels, defaults to 30
*
*/
if (!baseOptions.showHeader) {
baseOptions.headerRowHeight = 0;
}
else {
baseOptions.headerRowHeight = typeof(baseOptions.headerRowHeight) !== "undefined" ? baseOptions.headerRowHeight : 30;
}
/**
* @ngdoc property
* @name rowHeight
* @propertyOf ui.grid.class:GridOptions
* @description The height of the row in pixels, Can be passed as integer or string. defaults to 30.
*
*/
if (typeof baseOptions.rowHeight === "string") {
baseOptions.rowHeight = parseInt(baseOptions.rowHeight) || 30;
}
else {
baseOptions.rowHeight = baseOptions.rowHeight || 30;
}
/**
* @ngdoc integer
* @name minRowsToShow
* @propertyOf ui.grid.class:GridOptions
* @description Minimum number of rows to show when the grid doesn't have a defined height. Defaults to "10".
*/
baseOptions.minRowsToShow = typeof(baseOptions.minRowsToShow) !== "undefined" ? baseOptions.minRowsToShow : 10;
/**
* @ngdoc property
* @name showGridFooter
* @propertyOf ui.grid.class:GridOptions
* @description Whether or not to show the footer, defaults to false
* The footer display Total Rows and Visible Rows (filtered rows)
*/
baseOptions.showGridFooter = baseOptions.showGridFooter === true;
/**
* @ngdoc property
* @name showColumnFooter
* @propertyOf ui.grid.class:GridOptions
* @description Whether or not to show the column footer, defaults to false
* The column footer displays column aggregates
*/
baseOptions.showColumnFooter = baseOptions.showColumnFooter === true;
/**
* @ngdoc property
* @name columnFooterHeight
* @propertyOf ui.grid.class:GridOptions
* @description The height of the footer rows (column footer and grid footer) in pixels
*
*/
baseOptions.columnFooterHeight = typeof(baseOptions.columnFooterHeight) !== "undefined" ? baseOptions.columnFooterHeight : 30;
baseOptions.gridFooterHeight = typeof(baseOptions.gridFooterHeight) !== "undefined" ? baseOptions.gridFooterHeight : 30;
baseOptions.columnWidth = typeof(baseOptions.columnWidth) !== "undefined" ? baseOptions.columnWidth : 50;
/**
* @ngdoc property
* @name maxVisibleColumnCount
* @propertyOf ui.grid.class:GridOptions
* @description Defaults to 200
*
*/
baseOptions.maxVisibleColumnCount = typeof(baseOptions.maxVisibleColumnCount) !== "undefined" ? baseOptions.maxVisibleColumnCount : 200;
/**
* @ngdoc property
* @name virtualizationThreshold
* @propertyOf ui.grid.class:GridOptions
* @description Turn virtualization on when number of data elements goes over this number, defaults to 20
*/
baseOptions.virtualizationThreshold = typeof(baseOptions.virtualizationThreshold) !== "undefined" ? baseOptions.virtualizationThreshold : 20;
/**
* @ngdoc property
* @name columnVirtualizationThreshold
* @propertyOf ui.grid.class:GridOptions
* @description Turn virtualization on when number of columns goes over this number, defaults to 10
*/
baseOptions.columnVirtualizationThreshold = typeof(baseOptions.columnVirtualizationThreshold) !== "undefined" ? baseOptions.columnVirtualizationThreshold : 10;
/**
* @ngdoc property
* @name excessRows
* @propertyOf ui.grid.class:GridOptions
* @description Extra rows to to render outside of the viewport, which helps with smoothness of scrolling.
* Defaults to 4
*/
baseOptions.excessRows = typeof(baseOptions.excessRows) !== "undefined" ? baseOptions.excessRows : 4;
/**
* @ngdoc property
* @name scrollThreshold
* @propertyOf ui.grid.class:GridOptions
* @description Defaults to 4
*/
baseOptions.scrollThreshold = typeof(baseOptions.scrollThreshold) !== "undefined" ? baseOptions.scrollThreshold : 4;
/**
* @ngdoc property
* @name excessColumns
* @propertyOf ui.grid.class:GridOptions
* @description Extra columns to to render outside of the viewport, which helps with smoothness of scrolling.
* Defaults to 4
*/
baseOptions.excessColumns = typeof(baseOptions.excessColumns) !== "undefined" ? baseOptions.excessColumns : 4;
/**
* @ngdoc property
* @name horizontalScrollThreshold
* @propertyOf ui.grid.class:GridOptions
* @description Defaults to 4
*/
baseOptions.horizontalScrollThreshold = typeof(baseOptions.horizontalScrollThreshold) !== "undefined" ? baseOptions.horizontalScrollThreshold : 2;
/**
* @ngdoc property
* @name aggregationCalcThrottle
* @propertyOf ui.grid.class:GridOptions
* @description Default time in milliseconds to throttle aggregation calcuations, defaults to 500ms
*/
baseOptions.aggregationCalcThrottle = typeof(baseOptions.aggregationCalcThrottle) !== "undefined" ? baseOptions.aggregationCalcThrottle : 500;
/**
* @ngdoc property
* @name wheelScrollThrottle
* @propertyOf ui.grid.class:GridOptions
* @description Default time in milliseconds to throttle scroll events to, defaults to 70ms
*/
baseOptions.wheelScrollThrottle = typeof(baseOptions.wheelScrollThrottle) !== "undefined" ? baseOptions.wheelScrollThrottle : 70;
/**
* @ngdoc property
* @name scrollDebounce
* @propertyOf ui.grid.class:GridOptions
* @description Default time in milliseconds to debounce scroll events, defaults to 300ms
*/
baseOptions.scrollDebounce = typeof(baseOptions.scrollDebounce) !== "undefined" ? baseOptions.scrollDebounce : 300;
/**
* @ngdoc boolean
* @name enableSorting
* @propertyOf ui.grid.class:GridOptions
* @description True by default. When enabled, this setting adds sort
* widgets to the column headers, allowing sorting of the data for the entire grid.
* Sorting can then be disabled / enabled on individual columns using the columnDefs,
* if it set, it will override GridOptions enableSorting setting.
*/
baseOptions.enableSorting = baseOptions.enableSorting !== false;
/**
* @ngdoc boolean
* @name enableFiltering
* @propertyOf ui.grid.class:GridOptions
* @description False by default. When enabled, this setting adds filter
* boxes to each column header, allowing filtering within the column for the entire grid.
* Filtering can then be disabled on individual columns using the columnDefs.
*/
baseOptions.enableFiltering = baseOptions.enableFiltering === true;
/**
* @ngdoc boolean
* @name enableColumnMenus
* @propertyOf ui.grid.class:GridOptions
* @description True by default. When enabled, this setting displays a column
* menu within each column.
* By default column menu's trigger is hidden before mouse over, but you can always force it to be visible with CSS:
*
* <pre>
* .ui-grid-column-menu-button {
* display: block;
* }
* </pre>
*/
baseOptions.enableColumnMenus = baseOptions.enableColumnMenus !== false;
/**
* @ngdoc boolean
* @name enableVerticalScrollbar
* @propertyOf ui.grid.class:GridOptions
* @description {@link ui.grid.service:uiGridConstants#properties_scrollbars uiGridConstants.scrollbars.ALWAYS} by default.
* This settings controls the vertical scrollbar for the grid.
* Supported values: uiGridConstants.scrollbars.ALWAYS, uiGridConstants.scrollbars.NEVER
*/
baseOptions.enableVerticalScrollbar = typeof(baseOptions.enableVerticalScrollbar) !== "undefined" ? baseOptions.enableVerticalScrollbar : uiGridConstants.scrollbars.ALWAYS;
/**
* @ngdoc boolean
* @name enableHorizontalScrollbar
* @propertyOf ui.grid.class:GridOptions
* @description {@link ui.grid.service:uiGridConstants#properties_scrollbars uiGridConstants.scrollbars.ALWAYS} by default.
* This settings controls the horizontal scrollbar for the grid.
* Supported values: uiGridConstants.scrollbars.ALWAYS, uiGridConstants.scrollbars.NEVER
*/
baseOptions.enableHorizontalScrollbar = typeof(baseOptions.enableHorizontalScrollbar) !== "undefined" ? baseOptions.enableHorizontalScrollbar : uiGridConstants.scrollbars.ALWAYS;
/**
* @ngdoc boolean
* @name enableMinHeightCheck
* @propertyOf ui.grid.class:GridOptions
* @description True by default. When enabled, a newly initialized grid will check to see if it is tall enough to display
* at least one row of data. If the grid is not tall enough, it will resize the DOM element to display minRowsToShow number
* of rows.
*/
baseOptions.enableMinHeightCheck = baseOptions.enableMinHeightCheck !== false;
/**
* @ngdoc boolean
* @name minimumColumnSize
* @propertyOf ui.grid.class:GridOptions
* @description Columns can't be smaller than this, defaults to 10 pixels
*/
baseOptions.minimumColumnSize = typeof(baseOptions.minimumColumnSize) !== "undefined" ? baseOptions.minimumColumnSize : 10;
/**
* @ngdoc function
* @name rowEquality
* @methodOf ui.grid.class:GridOptions
* @description By default, rows are compared using object equality. This option can be overridden
* to compare on any data item property or function
* @param {object} entityA First Data Item to compare
* @param {object} entityB Second Data Item to compare
*/
baseOptions.rowEquality = baseOptions.rowEquality || function(entityA, entityB) {
return entityA === entityB;
};
/**
* @ngdoc string
* @name headerTemplate
* @propertyOf ui.grid.class:GridOptions
* @description Null by default. When provided, this setting uses a custom header
* template, rather than the default template. Can be set to either the name of a template file:
* <pre> $scope.gridOptions.headerTemplate = 'header_template.html';</pre>
* inline html
* <pre> $scope.gridOptions.headerTemplate = '<div class="ui-grid-top-panel" style="text-align: center">I am a Custom Grid Header</div>'</pre>
* or the id of a precompiled template (TBD how to use this).
* </br>Refer to the custom header tutorial for more information.
* If you want no header at all, you can set to an empty div:
* <pre> $scope.gridOptions.headerTemplate = '<div></div>';</pre>
*
* If you want to only have a static header, then you can set to static content. If
* you want to tailor the existing column headers, then you should look at the
* current 'ui-grid-header.html' template in github as your starting point.
*
*/
baseOptions.headerTemplate = baseOptions.headerTemplate || null;
/**
* @ngdoc string
* @name footerTemplate
* @propertyOf ui.grid.class:GridOptions
* @description (optional) ui-grid/ui-grid-footer by default. This footer shows the per-column
* aggregation totals.
* When provided, this setting uses a custom footer template. Can be set to either the name of a template file 'footer_template.html', inline html
* <pre>'<div class="ui-grid-bottom-panel" style="text-align: center">I am a Custom Grid Footer</div>'</pre>, or the id
* of a precompiled template (TBD how to use this). Refer to the custom footer tutorial for more information.
*/
baseOptions.footerTemplate = baseOptions.footerTemplate || 'ui-grid/ui-grid-footer';
/**
* @ngdoc string
* @name gridFooterTemplate
* @propertyOf ui.grid.class:GridOptions
* @description (optional) ui-grid/ui-grid-grid-footer by default. This template by default shows the
* total items at the bottom of the grid, and the selected items if selection is enabled.
*/
baseOptions.gridFooterTemplate = baseOptions.gridFooterTemplate || 'ui-grid/ui-grid-grid-footer';
/**
* @ngdoc string
* @name rowTemplate
* @propertyOf ui.grid.class:GridOptions
* @description 'ui-grid/ui-grid-row' by default. When provided, this setting uses a
* custom row template. Can be set to either the name of a template file:
* <pre> $scope.gridOptions.rowTemplate = 'row_template.html';</pre>
* inline html
* <pre> $scope.gridOptions.rowTemplate = '<div style="background-color: aquamarine" ng-click="grid.appScope.fnOne(row)" ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ui-grid-cell></div>';</pre>
* or the id of a precompiled template (TBD how to use this) can be provided.
* </br>Refer to the custom row template tutorial for more information.
*/
baseOptions.rowTemplate = baseOptions.rowTemplate || 'ui-grid/ui-grid-row';
/**
* @ngdoc string
* @name gridMenuTemplate
* @propertyOf ui.grid.class:GridOptions
* @description 'ui-grid/uiGridMenu' by default. When provided, this setting uses a
* custom grid menu template.
*/
baseOptions.gridMenuTemplate = baseOptions.gridMenuTemplate || 'ui-grid/uiGridMenu';
/**
* @ngdoc object
* @name appScopeProvider
* @propertyOf ui.grid.class:GridOptions
* @description by default, the parent scope of the ui-grid element will be assigned to grid.appScope
* this property allows you to assign any reference you want to grid.appScope
*/
baseOptions.appScopeProvider = baseOptions.appScopeProvider || null;
return baseOptions;
}
};
}]);
})();