-
Notifications
You must be signed in to change notification settings - Fork 20
/
px-data-grid-paginated.html
1255 lines (1167 loc) · 47.7 KB
/
px-data-grid-paginated.html
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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!--
Copyright (c) 2018, General Electric
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../vaadin-grid/vaadin-grid.html">
<link rel="import" href="../vaadin-grid/vaadin-grid-selection-column.html">
<link rel="import" href="../vaadin-grid/vaadin-grid-sorter.html">
<link rel="import" href="../px-spinner/px-spinner.html">
<link rel="import" href="px-data-grid.html">
<link rel="import" href="px-data-grid-column.html">
<link rel="import" href="px-auto-filter-field.html">
<link rel="import" href="px-data-grid-navigation.html">
<link rel="import" href="px-data-grid-theme.html">
<link rel="import" href="px-data-grid-selection-column.html">
<link rel="import" href="../app-localize-behavior/app-localize-behavior.html"/>
<link rel="import" href="px-data-grid-string-renderer.html">
<link rel="import" href="px-data-grid-cell-content-wrapper.html">
<link rel="import" href="css/px-data-grid-paginated-styles.html">
<dom-module id="px-data-grid-paginated">
<template>
<style include="px-data-grid-paginated-styles"></style>
<px-data-grid
remote-data-provider="{{_currentDataProvider}}"
selection-mode="{{selectionMode}}"
selected-items="{{selectedItems}}"
hide-selection-column="{{hideSelectionColumn}}"
resizable="{{resizable}}"
striped="{{striped}}"
ellipsis="{{ellipsis}}"
multi-sort="{{multiSort}}"
columns="{{columns}}"
column-reordering-allowed="{{columnReorderingAllowed}}"
hide-column-filter="{{hideColumnFilter}}"
hide-action-menu="{{hideActionMenu}}"
language="{{language}}"
resources="{{resources}}"
auto-filter="{{autoFilter}}"
grid-height="{{gridHeight}}"
item-id-path="{{itemIdPath}}"
table-actions="{{tableActions}}"
item-actions="{{itemActions}}"
offer-filter-saving="{{offerFilterSaving}}"
filterable="{{filterable}}"
editable="{{editable}}"
highlight="{{highlight}}"
default-column-width="{{defaultColumnWidth}}"
default-column-flex-grow="{{defaultColumnFlexGrow}}"
disable-all-columns-filter={{disableAllColumnsFilter}}
string-comparators="{{stringComparators}}"
number-comparators="{{numberComparators}}">
</px-data-grid>
<px-data-grid-navigation
total-item-count="[[size]]"
on-navigation-change="_onNavigationChange"
selectable-page-sizes="[[selectablePageSizes]]"
page-size="[[pageSize]]"
current-page="[[page]]"
number-of-pages="[[_calcNumPages(size, pageSize)]]"
hide-page-list="[[_hidePageList(autoHidePageList, size, pageSize)]]"
hide-page-size-select="[[_hidePageSizeSelect(autoHidePageSizeSelect, size, selectablePageSizes)]]"
language="[[language]]"
resources="[[resources]]">
</px-data-grid-navigation>
</template>
<script>
{
/**
* `<px-data-grid-paginated>` - Predix UI component which defines a paginated data grid.
*
* Due to incompatibility of paginated grid with features in the list below, these won't
* be available for px-data-grid-paginated:
*
* - Group By Column
* - Select All checkbox in `<px-data-grid-selection-column>`
*/
class DataGridPaginatedElement extends Polymer.mixinBehaviors([Polymer.AppLocalizeBehavior], Polymer.Element) {
static get is() {
return 'px-data-grid-paginated';
}
static get properties() {
return {
// UNIQUE PROPERTIES FOR PX-DATA-GRID-PAGINATED
/**
* Array of selectable page sizes offered to the user.
*/
selectablePageSizes: {
type: Array,
value: [10, 20, 30]
},
/**
* Current page number of displayed items. Page 1 should be the minimum value.
*/
page: {
type: Number,
value: 1,
observer: '_onPageChange'
},
/**
* Set to automatically hide the page numbers when there is only
* 1 page available.
*/
autoHidePageList: {
type: Boolean,
value: false
},
/**
* Set to automatically hide the page size select when there is only
* 1 page available and it's smaller or equal to the smallest of the selectable page sizes.
*/
autoHidePageSizeSelect: {
type: Boolean,
value: false
},
// PROPERTIES SHARED WITH PX-DATA-GRID
/**
* Data for the table to display.
*
* Pass an array of objects. Each object will be rendered as a row
* in the grid. The objects should share many of the same keys.
* Each key will be used to group data into columns.
*
* Use the `columns` property to control which keys are displayed
* to the user and which are not, and to control how the grid
* handles the data for each column. By default if no `columns` are
* defined the grid will automatically create columns from all of
* the keys found in the first object.
*
* Example data:
*
* ```
* [
* {
* first: 'Elizabeth',
* last: 'Wong',
* email: '[email protected]'
* },
* {
* first: 'Jeffrey',
* last: 'Hamilton',
* email: '[email protected]'
* },
* {
* first: 'Alma',
* last: 'Martin',
* email: '[email protected]'
* }
* ]
* ```
*/
tableData: {
type: Array,
notify: true
},
/**
* Set to hide the selection checkbox for each row.
*
* By default, if the `selectionMode` property is set to `'single'`
* or `'multi'` the grid shows a checkbox/radio button the user
* can click to select or deselect a row. When this property is
* enabled, the checkbox is hidden and the user can click directly
* on row contents to select or deselect a row.
*/
hideSelectionColumn: {
type: Boolean,
value: false
},
/**
* Array of selected items. Automatically updated by the grid when
* the user selects items. Each item will be a reference to the
* `tableData` item that was passed to render the row.
*
* Add references to `tableData` items to programmatically select
* items from your application.
*/
selectedItems: {
type: Array,
value: () => [],
notify: true
},
// @TODO: Improve docs for size
/**
* The total number of items
*/
size: {
type: Number,
value: undefined,
observer: '_ensureValidPageNumber'
},
/**
* For paginated grid, the number of items visible in a single
* page. Set to a higher number to show more items.
*
* `pageSize` is also used to set the number of items fetched
* during each request to the `remoteDataProvider` if one is used.
* See the `remoteDataProvider` property for more information.
*/
pageSize: {
type: Number,
value: 10,
observer: '_onPageSizeChange'
},
/**
* When `true`, user can sort by multiple columns
*/
multiSort: {
type: Boolean,
value: false
},
/**
* Sets the current selection mode for the grid. Valid modes are:
*
* * `'none'` - User can't select any rows
* * `'single'` - User can select one row at a time
* * `'multi'` - User can select multiple rows at the same time
*/
selectionMode: {
type: String,
value: 'none'
},
// @TODO: Improve docs for activeItem
/**
* The item user has last interacted with. Turns to `null` after user deactivates
* the item by re-interacting with the currently active item.
*/
activeItem: {
type: Object,
notify: true,
value: null
},
/**
* Set to `true` to allow the user to resize columns.
*/
resizable: {
type: Boolean,
value: false
},
/**
* Set to allow users to edit data in the grid. You must also
* explicitly set the `columns.editable` property to true for each
* column the user can edit in the grid.
*
* When the user starts or stops editing a row the
* `editing-item-changed` event will be fired. `event.detail.item`
* will contain a reference to the row being edited.
*
* After a user finishes editing a row the `item-edited` event
* will be fired. `event.detail` will contain information about
* what the user changed.
*/
editable: {
type: Boolean,
value: false
},
/**
* Set to `true` to allow the user to re-order columns by dragging
* and dropping them. Can't be combined with some other states like
* group-by-value.
*/
columnReorderingAllowed: {
type: Boolean,
value: false
},
/**
* An array containing references to the expanded rows.
*
* Automatically updated by the grid in the following cases:
*
* * When a `row-details` template is provided to create expandable
* rows the grid will add rows to this list when they are
* expanded by the user, and remove rows when they are collapsed
* by the user.
* * When the user groups rows by column the grid will add rows
* that the user expands and remove rows the user collapses.
*
* Set this value to references to rows to expand or collapse
* the rows programmatically.
*/
expandedItems: {
type: Array,
value: []
},
/**
* If set, will remove the "Any column" filter from the Advanced Filter dialog.
*/
disableAllColumnsFilter: {
type: Boolean,
value: false
},
/**
* Set to hide the action menu button displayed at the top right of
* the grid.
*
* If the action menu is hidden, the user will not be able to unhide
* any hidden columns.
*/
hideActionMenu: {
type: Boolean,
value: false
},
/**
* Defines the columns the grid should render. If no columns are
* passed, the grid generates columns from the `tableData` passed
* in. Columns are rendered in the same order as the array.
*
* ## `column` options
*
* The following options are available for all column types. Only
* `name` and `path` are required, all others are optional:
*
* * `{string} name` - Human-readable name displayed in the column
* header
*
* * `{string} path` - Key used to get the column data from each
* of the `tableData` objects
*
* * `{string} id='column.path[column.type]'` - Unique identifier
* of the column. By default, px-data-grid will automatically
* generate it from `column.path` and `column.type`. There can't
* be 2 columns with the same id. The value `-any-` is a
* reserved keyword that you cannot use for any column `id`.
*
* * `{string} type=('string'|'number'|'date')` - Type of data
* in the column. Used in the advanced filter UI to show
* different filter options for each data type. Does not change
* the renderer or impact sorting.
*
* * `{string} renderer` - The name of the web component used to
* render each cell in the column. There are three built-in
* renderers available: `'px-data-grid-string-renderer'` (the
* default renderer), `'px-data-grid-number-renderer'`, and
* `'px-data-grid-date-renderer'`. You can also create a custom
* renderer and use its name here. If no renderer is specified,
* the column cannot be edited by the user.
*
* * `{object} rendererConfig` - Settings to pass to the renderer
* that change how data is displayed to the user. See the
* examples below for information on which options are available
* for each built-in renderer.
*
* The following options are available for columns of type `date`:
*
* * `{array} dateRanges` - List of pre-defined date ranges that
* will appear in advanced filter dropdown for this column.
* See the examples below for examples on how to format
* each date range.
*
* The following options are available for columns of type `number`:
*
* * `{number} minBound` - Defines a minimum bound of a number in
* the advanced filter field for this column. If both minBound
* and maxBound properties are defined, the advanced filter will
* display a slider instead of a condition dropdown.
*
* * `{number} maxBound` - Defines a maximum bound of a number in
* the advanced filter field for this column.
*
* * `{boolean} hidden=false` - Hides the column from the user
* when the grid is rendered. Automatically updated when the
* user shows/hides columns using action menu(s).
*
* * `{boolean} frozen=false` - Freezes the column. When the user
* scrolls the grid horizontally frozen columns will not move.
* Automatically updated when the user freezes/unfreezes columns
* using action menu(s).
*
* * `{boolean} required=false` - Used in renderers during editing.
* If the column is required, the user will not be allowed to
* enter a blank value.
*
* * `{number} flexGrow=1` - Sets the relative size of the column
* compared to other columns in the grid. Equivalent to the CSS
* `flex-grow` property.
*
*
* ## `column.dateFormat` options
*
* The following options can be set in the `dateFormat` for
* columns of type `date`. All formats should be set to a valid
* [moment.js format string](https://momentjs.com/docs/#/parsing/string-format/)
* or to 'ISO':
*
* * `{string} dateFormat.format='YYYY-MM-DD"T"HH:mm:ss.SSSS'` -
* Format used to read the date/timestamp data.
*
* * `{string} dateFormat.timezone='UTC'` -
* Timezone used to read the date/timestamp data.
*
* Date parsing uses moment's [forgiving mode](https://momentjs.com/guides/#/parsing/forgiving-mode/), which can produce
* silent but highly undesirable parsing errors if the date format does not match the source data.
* If your source data is formatted differently to ISO8601, it is critical that you
* configure the `format` property correctly.
*
* ## `column.rendererConfig` options
*
* The following options can be set in the `rendererConfig` for
* columns of type `date`. All formats should be set to a valid
* [moment.js format string](https://momentjs.com/docs/#/parsing/string-format/)
* or to 'ISO':
*
* * `{string} rendererConfig.displayFormat='YYYY-MM-DD'` -
* Format used to display the date for the user.
*
* * `{string} rendererConfig.dataFormat='YYYY-MM-DD'` - Format
* the grid expects data in when reading it from `tableData`.
*
* * `{string} rendererConfig.datePickerDateFormat='YYYY-MM-DD'` -
* Format used for the px-datetime-picker date when the user
* edits cells in the column.
*
* * `{string} rendererConfig.datePickerTimeFormat='HH:MM:SS'` -
* Format used for the px-datetime-picker time when the user
* edits cells in the column.
*
* * `{boolean} rendererConfig.hideDate=false` - Hides the date
* section of the px-datetime-picker when the user edits cells
* in the column.
*
* * `{boolean} rendererConfig.hideTime=true` - Hides the time
* section of the px-datetime-picker when the user edits cells
* in the column.
*
* The following options can be set in the `rendererConfig` for
* columns of type `number`:
*
* * `{?string} rendererConfig.displayFormat=null` - Format used to
* display numbers in this column. Set to a valid
* [numbro.js format string](http://numbrojs.com/format.html).
* Set to `null` to display the number exactly as it appears
* in the `tableData` by coercing it to string.
*
* * `{string} rendererConfig.displayCulture='en-US'` - Changes the
* way numbers in this column are displayed to the user by
* localizing to get the correct format for commas, decimals,
* etc. See [numbro.js languages](http://numbrojs.com/languages.html)
* for a list of valid options.
*
* * `{boolean} rendererConfig.displayIsCurrency=false` - Set to
* `true` if the data in this column should be formatted as
* currency. Will use `rendererConfig.displayFormat` to figure
* out how to display the currency, or fall back to a localized
* default based on `rendererConfig.displayCulture`.
*
* * `{string} displayZeroFormat` - Used to format numbers equal
* to `0` in this column. See [numbro.js docs](http://numbrojs.com/format.html)
* for a list of valid options.
*
* ## Examples
*
* Example format for a single column with all configurations used:
*
* ```javascript
* {
* id: 'first[string]',
* name: 'First Name',
* path: 'first',
* type: 'string',
* renderer: 'px-data-grid-string-renderer',
* rendererConfig: {
* customInfo: 'some info',
* customInfo2: 42
* },
* dateRanges: [
* {
* name: 'Last 7 days',
* getRange: () => {
* return {
* // use timezone of source data
* dateTo: window.moment().tz('UTC').format(),
* dateFrom: window.moment().tz('UTC').subtract(7, 'd').format()
* };
* }
* },
* {
* name: 'Fixed range',
* range: {
* dateTo: '1996-11-10',
* dateFrom: '1985-12-19'
* }
* }
* ],
* minBound: 1,
* maxBound: 10,
* hidden: false,
* frozen: false,
* required: false,
* flexGrow: 1
* }
* ```
*
* Example format for column of type `date` with custom `dateRanges`:
*
* ```javascript
* {
* name: 'Birth date',
* path: 'birth_date',
* type: 'date',
* editable: true,
* renderer: 'px-data-grid-date-renderer',
* rendererConfig: {
* hideTime: true,
* displayFormat: 'YYYY/MM/DD',
* dataFormat: 'YYYY-MM-DD'
* },
* dateRanges: [
* {
* name: 'Last 7 days',
* getRange: () => {
* return {
* // use timezone of source data
* dateTo: window.moment().tz('UTC').format(),
* dateFrom: window.moment().tz('UTC').subtract(7, 'd').format()
* };
* }
* },
* {
* name: 'Last 14 days',
* getRange: () => {
* return {
* // use timezone of source data
* dateTo: window.moment().tz('UTC').format(),
* dateFrom: window.moment().tz('UTC').subtract(14, 'd').format()
* };
* }
* },
* {
* name: 'This month',
* getRange: () => {
* return {
* // use timezone of source data
* dateTo: window.moment().tz('UTC').format(),
* dateFrom: window.moment().tz('UTC').subtract(31, 'd').format()
* };
* }
* },
* {
* name: 'Last month',
* getRange: () => {
* return {
* // use timezone of source data
* dateTo: window.moment().tz('UTC').subtract(1, 'M').format(),
* dateFrom: window.moment().tz('UTC').subtract(2, 'M').format()
* };
* }
* },
* {
* name: 'Fixed range',
* range: {
* dateTo: '1996-11-10',
* dateFrom: '1985-12-19'
* }
* }
* ]
* }
* ```
*/
columns: {
type: Array
},
/**
* A valid IETF language tag as a string that `app-localize-behavior`
* will use to localize this component.
*
* See https://github.com/PolymerElements/app-localize-behavior for
* API documentation and more information.
*/
language: {
type: String,
value: 'en'
},
/**
* Use the key for localization if value for that language is missing.
* Should always be true for Predix components.
*/
useKeyIfMissing: {
type: Boolean,
value: true
},
/**
* Library object of hardcoded strings used in this application.
* Used by `app-localize-behavior` in conjunction with `language`.
*/
resources: {
type: Object,
value: () => {
return {
'en': {
'Rows per page': 'Rows per page',
'of {total}': 'of {total}'
},
'fr': {
'Rows per page': 'Lignes par page',
'of {total}': 'sur {total}'
},
'fi': {
'Rows per page': 'Riviä / sivu',
'of {total}': '/ {total}'
}
};
}
},
/**
* A list of custom actions that are shown when the user taps the
* action menu button at the top right of the grid. If the
* `hideActionMenu` property is enabled the action menu won't be
* shown to the user.
*
* Each array entry should be an object with the following properties:
*
* * `{string} name` - Label shown in the action menu, should
* prompt the user to do something (e.g. "Export CSV")
* * `{string} id` - Unique identifier that will be included in the
* event fired when the user taps an action in the menu
*
* When the user taps an action in the menu the grid will fire the
* `table-action` event. `event.detail.id` will be the action ID.
*
* Example actions:
*
* ```javascript
* [
* {
* name: 'Export CSV',
* id: 'CSV'
* }
* {
* name: 'Export Excel',
* id: 'Excel'
* }
* ]
* ```
*/
tableActions: {
type: Array,
},
/**
* Set to `true` to allow the user to hide the column filter/selector in
* the action menu.
*/
hideColumnFilter: {
type: Boolean,
value: false
},
/**
* A list of custom actions that are shown in the actions menu
* for each data row. The action menu button appears to the right
* of each row when the user hovers over the row.
*
* Each array entry should be an object with the following properties:
*
* * `{string} name` - Label shown in the action menu, should
* prompt the user to do something (e.g. "Add Row After")
* * `{string} id` - Unique identifier that will be included in the
* event fired when the user taps an action in the menu
*
* When the user taps an action in the menu the grid will fire the
* `item-action` event. `event.detail.id` will be the action ID and
* `event.detail.item` will be a reference to the row the user
* took action on (from `tableData`).
*
* Example actions:
*
* ```javascript
* [
* {
* name: 'Add Row After',
* id: 'add-after'
* }
* {
* name: 'Delete Row',
* id: 'delete'
* }
* ]
* ```
*/
itemActions: {
type: Array
},
/**
* Function that provides items lazily. Receives arguments `params`, `callback`:
*
* `params.page` Requested page index
*
* `params.pageSize` Current page size
*
* `params.filters` Currently applied filters
*
* `params.sortOrders` Currently applied sorting orders
*
* `params.parentItem` When expandable table is used, and sublevel items
* are requested, reference to parent item of the requested sublevel.
* Otherwise `undefined`.
*
* `callback(items, size)` Callback function with arguments:
* - `items` Current page of items
* - `size` Total number of items.
*
* `<px-data-grid>` calls this function lazily, only when it needs more data
* to be displayed.
*
* __Also, note that when using function data providers, the total number of items
* needs to be set manually. The total number of items can be returned
* in the second argument of the data provider callback:__
*
* ```javascript
* pxDataGrid.dataProvider = function(params, callback) {
* var url = 'https://api.example/data' +
* '?page=' + params.page + // the requested page index
* '&per_page=' + params.pageSize; // number of items on the page
* var xhr = new XMLHttpRequest();
* xhr.onload = function() {
* var response = JSON.parse(xhr.responseText);
* callback(
* response.employees, // requested page of items
* response.totalSize // total number of items
* );
* };
* xhr.open('GET', url, true);
* xhr.send();
* };
* ```
*
* __Alternatively, you can use the `size` property to set the total number of items:__
*
* ```javascript
* pxDataGrid.size = 200; // The total number of items
* pxDataGrid.dataProvider = function(params, callback) {
* var url = 'https://api.example/data' +
* '?page=' + params.page + // the requested page index
* '&per_page=' + params.pageSize; // number of items on the page
* var xhr = new XMLHttpRequest();
* xhr.onload = function() {
* var response = JSON.parse(xhr.responseText);
* callback(response.employees);
* };
* xhr.open('GET', url, true);
* xhr.send();
* };
* ```
*/
remoteDataProvider: {
type: Function,
observer: '_remoteDataProviderChanged'
},
_currentDataProvider: {
type: Function
},
/**
* Set to add a background color to every other row in the grid.
* Can make it easier for users to scan across long rows. Striping
* is disabled in group-by-column mode.
*/
striped: {
type: Boolean,
value: false
},
/**
* Set to show an ellipsis and truncate text for columns where the
* text doesn't fit in the column.
*
* Do not enable wrap mode while ellipsis mode is enabled.
*/
ellipsis: {
type: Boolean,
value: false
},
/**
* Number of milliseconds to wait before showing the loading spinner
* when requesting new data from the `remoteDataProvider`.
*/
loadingSpinnerDebounce: {
type: Number,
value: 500
},
/**
* Set to `true` to enable simple filtering. When enabled, a search
* box will be shown at the top of the grid. The user can type
* in the search box to hide rows that don't include the stringified
* value they're looking for. The grid will search all columns and
* treat all column types as strings for matching purposes.
*
* See `filterable` property for a more advanced filter option.
*/
autoFilter: {
type: Boolean,
value: false
},
/**
* List of rules used to highligh specific columns, rows, or cells.
*
* Pass an array of objects. Each object should have the following
* properties:
*
* * `{string} type` - If the highlight condition returns `true`,
* the type determines what the grid will highlight. Set to
* `'cell'` to highlight only the cell that passed the highlight
* rule, `'row'` to highlight the row that holds the matching
* cell, or `'column'` to highlight the column that holds the
* matching cell.
* * `{Function} condition` - Function that will be called by the
* grid for each cell. If the function returns `true`, the
* highlight rule will be triggered. If the function returns a
* falsey value, the highlight rule will not be used. The function
* will be passed three arguments: `cellContent` containing
* the text of the cell, `column` containing a reference to the
* `columns` object for the cell's column, and `item` as a reference
* to the `tableData` item used to create the cell's row.
* * `{string} color` - A valid CSS color (e.g. hex code or color
* name). If the highlight condition returns `true`, the color
* will be used to set the background color of the matching
* cell, column, or row.
*
* Example highlight rules:
*
* ```javascript
* [
* {
* type: 'cell',
* condition: (cellContent, column, item) => { return cellContent == 'John Doe' },
* },
* {
* type: 'row',
* condition: (cellContent, item) => { return cellContent[0] == 'a' },
* color: '#a8a8a8'
* },
* {
* type: 'column',
* condition (column, item) => { return column.name == 'age' },
* color: 'pink'
* }
* ]
* ```
*/
highlight: {
type: Array
},
/**
* When true data provider is local, when false external (remote) and
* when undefined it defined yet.
*/
_hasLocalDataProvider: {
type: Boolean
},
/**
* Default width for columns. Defaults to `100px` if undefined.
*
* Column sizes should also be configured using the
* `defaultColumnFlexGrow` and `columns.flexGrow` properties to
* change how each column sizes itself relative to other columns in
* the grid.
*
* When column flex-grow properties are set to non-zero values,
* this size behaves as a minimum width for the column.
*/
defaultColumnWidth: {
type: String
},
/**
* Default flex-grow value for columns if none is defined in
* `columns.flexGrow`. Equivalent to the CSS flex-grow property.
*/
defaultColumnFlexGrow: {
type: Number
},
/**
* Defines the height of grid.
*
* * Set to `'auto'` if the grid should grow to fit all of its rows
* * Set to `'default'` or undefined to use the default height
* * Set to any other valid CSS height valid (e.g. `400px`) to
* define a static height for the grid area inside the
* px-data-grid. This height will not include the table action
* menu and other elements of the grid.
*
* See the `flexToSize` property for a different strategy that sizes
* the grid based on its parent element's height.
*/
gridHeight: {
type: String,
value: 'auto'
},
/**
* Path to a `tableData` item sub-property that serves as a unique
* identifier for the item. Should be defined if the grid allows
* user editing so the grid can pair new versions of each item
* with the original data.
*
* Path must be unique for each item, must exist for every item,
* and should not be changed or be user editable.
*/
itemIdPath: {
type: String
},
/**
* Set to allow users to save filters created in the advanced filter
* dialog. If enabled, the grid will fire `save-filters` events when
* the user taps the save filter button.
*/
offerFilterSaving: {
type: Boolean
},
/**
* Set to enable advanced filtering. When enabled, a filter
* button will be shown at the top of the grid. When the user clicks
* on the filter button, a modal will be shown and the user can
* filter visible items using different UI patterns.
*
* Columns should have the right `columns.type` set to ensure the
* advanced filtering works as expected. See the `columns` property
* for more information on setting the type, and for more advanced
* filtering options that can be customized for `number` and `date`
* type columns.
*/
filterable: {
type: Boolean,
value: false
},
/**
* Comparison options shown in the advanced filtering UI for columns
* of type `string`. Valid options are:
*
* * `'equals'`
* * `'contains'`
* * `'starts_with'`
* * `'ends_with'`
* * `'wildcard'`
*
* If this array is undefined or empty, all options will be shown.
*/
stringComparators: {
type: Array
},
/**
* Comparison options shown in the advanced filtering UI for columns
* of type `number`. Valid options are:
*
* * `'less_than'`
* * `'equals'`