aboutsummaryrefslogtreecommitdiffstats
path: root/vaadin-grid/vaadin-grid-doc.html
blob: 838bcd71d2f73c3fee95554b12a49943c980cb7f (plain)
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
<!-- Documentation of v-grid -->
<link rel='import' href='vaadin-grid.html'>

<!--
Represents a column definition of the grid.
-->
<dom-module id="Column"></dom-module>
<script>
  Polymer({
    is: 'Column',
    properties: {
      /**
       * Must be a valid JS variable name so that the same name can be used in 
       * the data source object fields.
       */
      name:  String,
      /**
       * Sets the content of this column in the default header row object
       */
      headerContent:  String,
      /**
       * Indicates whether the data in this column can be sorted by the end user
       *
       * @property sortable
       * @type boolean
       * @default false
       */
      sortable: false,
      /**
       * Indicates whether the data in this column can be edited using the row editor
       *
       * @property readOnly
       * @type boolean
       * @default false
       */
      readOnly: false,
      /**
       * Pixel values are supported only.
       *
       * @property minWidth
       * @type number
       * @default 10
       */
      minWidth: Number,
      /**
       * Pixel values are supported only.
       */
      maxWidth: Number,
      /**
       * Pixel values are supported only.
       */
      width: Number,
      /**
       * Defines the flex ratio of this column (expand ratio in Vaadin-speak). Expects an integer.
       *
       * @property flex
       * @type number
       * @default -1
       */
      flex: Number,
      /**
       * It is a function which should return the value of the column cell 
       * (passed on to the renderer function if defined).
       *  
       *  Example:
       *  ```
       *  column.valueGenerator = function(row) {
       *      return "> " + row.name;
       *  };
       *  ```
       *
       * Params:
       *  - {Row} row – Reference to the Row object
       *
       * @property valueGenerator
       * @type {function}
       */
      valueGenerator: Object,
      /**
       * It is a function which defines the custom renderer for this columns data items.
       *
       *  Example:
       *  ```
       *  column.renderer = function(cell) {
       *      cell.element.innerHTML = '$' + cell.data;
       *  };
       *  ```
       *
       * Params:
       *  - {Cell} cell – Reference to the Cell object
       *
       * @property renderer
       * @type {function}
       */
      renderer: Object
    }
  });
</script>

<!--
The object used to manipulate data in the grid.
-->
<dom-module id="Data"></dom-module>
<script>
  Polymer({
    is: 'Data',
    properties: {
      /**
       * The data source object for the grid.
       * 
       * If an array is used, it is wrapped with a function internally. 
       * Reading the property value will still return the array.       *
       *
       *  Example:
       *  ```
       *  data.source = [
       *      ["horse", 150, "domestic"],
       *      ["wolf", 100, "wild"]
       *  };
       *  ```
       * or
       *  ```
       *  var myArray = [...];
       *  data.source = function(req) {
       *      var from = req.index;
       *      var to = req.index + req.count;
       *      var array = myArray.slice(from, to);
       *
       *      req.success(array, data.length);
       *  };
       *  ```
       *
       * Params:
       *  - {DataRequest} req – Reference to the DataRequest object
       *
       * @property source
       * @type {Array|function}
       */
      source: Object,
      /**
       * The sort order.
       * 
       * @property source
       * @type {Array<SortOrder>}
       */
      sortOrder: Array
    }
  });
</script>

<!--
This is the object used when the grid request more data from datasources.
-->
<dom-module id="DataRequest"></dom-module>
<script>
  Polymer({
    is: 'DataRequest',
    properties: {
      /**
       * First data item index to fetch
       */
      index:  Number,

      /**
       * Number of data items to fetch
       */
      count:  Number
    },
    /**
     * Callback function to pass along the data items to the grid and the total size of the data source.
     *
     *  Example:
     *  ```
     *  var myArray = [...];
     *
     *  var from = req.index;
     *  var to = req.index + req.count;
     *  var array = myArray.slice(from, to);
     *
     *  req.success(array, data.length);
     *  ```
     *
     * @method success
     * @param {Array<*>} items The subset of the data items
     * @param {number} totalSize – The total quantity of the data items
     */
    success: function(items, totalSize) {},
    /**
     * Callback function to inform the grid that something failed when getting the data.
     *
     *  Example:
     *  ```
     *  req.failure();
     *  ```
     *
     * @method failure
     */
    failure: function() {}
  });
</script>

<!--
Configuration object for the embedded editor.
-->
<dom-module id="Editor"></dom-module>
<script>
  Polymer({
    is: 'Editor',
    properties: {
      /**
       * Whether grid is editable or not
       *
       * @property enabled
       * @type boolean
       */
      enabled: Boolean,
      /**
       * The save button caption
       *
       * @property saveButtonText
       * @type String
       * @default "Save"
       */
      saveButtonText: String,
      /**
       * The cancel button caption
       *
       * @property saveButtonText
       * @type String
       * @default "Cancel"
       */
      cancelButtonText: String,
      /**
       * The editor handler object the user should specify if the save and cancel 
       * actions should be handled somehow (e.g. send the saved data back to the 
       * server or just update a local array)
       *
       * @property handler
       * @type {EditorHandler}
       */
      handler: Object
    },
    /**
     * Activates the row editor for the given row index.
     *
     *  Example:
     *  ```
     *  editor.editRow(4);
     *  ```
     *
     * Params:
     *  - {number} rowIndex – The row index which should be edited
     *
     * @property editRow
     * @type {function}
     */
    editRow: Object,
    /**
     * Invokes the editor.handler.save function, if a handler is defined
     *
     * @property save
     * @type {function}
     */
    save: Object,
    /**
     * Invokes the editor.handler.cancel function, if a handler is defined
     *
     * @property cancel
     * @type {function}
     */
    cancel: Object
  });
</script>

<!--
The Object with all methods necessary for handling editor actions.
-->
<dom-module id="EditorHandler"></dom-module>
<script>
  Polymer({
    is: 'EditorHandler',
    properties: {
      /**
       * Handles the setting of data into the custom editor elements.
       * The default implementation expects that the editor element
       * (returned by getCellEditor) has a ‘value’ property which it sets.
       *
       * Params:
       *  - {EditorRequest} req – The editor handler request
       *
       * @property bind
       * @type {function}
       */
      bind: Object,
      /**
       *
       * Params:
       *  - {EditorRequest} req – The editor handler request
       *
       * @property cancel
       * @type {function}
       */
      cancel: Object,
      /**
       *
       * Params:
       *  - {EditorRequest} req – The editor handler request
       *
       * @property save
       * @type {function}
       */
      save: Object,
      /**
       * Returns HTML elements which are used for the editors in the row editor. 
       * This function is only called for the columns which have the editable 
       * property set to true. The default implementation returns &lt;input> elements 
       * for all editable columns.
       *
       * Params:
       *  - {Column} column – The column object for which to provide an editor
       *
       * @property getCellEditor
       * @type {function}
       */
      getCellEditor: Object
    }
  });
</script>

<!--
The object passed to the EditorHandler when a edition action is performed.
-->
<dom-module id="EditorRequest"></dom-module>
<script>
  Polymer({
    is: 'EditorRequest',
    properties: {
      /**
       * The row index
       */
      rowIndex:  Number,
      /**
       * The item from the data source array which is edited
       * 
       * @property dataItem
       * @type {*}
       */
      dataItem: Object,
      /**
       * Reference to the &lt;table is=v-grid> element
       *
       * @property grid
       * @type {HTMLElement}
       */
      grid:  Object
    },
    /**
     * The user should call this method to indicate that the request was handled successfully.
     *
     * @method success
     * @param {number} rowIndex The index of the row modified rowObject: 
     * the modified row as it could be used in the datasource.dataUpdated
     */
    success: function(rowIndex) {},
    /**
     * The user should call this method to indicate that the request was not handled successfully, 
     * and pass the error message and any erroneous columns as parameters.
     *
     * @method failure
     * @param {String} errorMsg The error message which should be shown in the row editor footer
     * @param {Array<Column>} errorColumns The editors which have errors
     */
    failure: function(errorMsg, errorColumns) {},
    /**
     * This function should return the editor element for the referenced column 
     * (same element which was created by the editor.handler.getCellEditor).
     *
     * @method getCellEditor
     * @param {Column} column The column object for which to provide an editor
     */
    getCellEditor: function(column) {}
  });
</script>

<!--
Object for manipulating footer rows.
-->
<dom-module id="Footer"></dom-module>
<script>
  Polymer({
    is: 'Footer',
    properties: {
      /**
       * The number of columns which this cell should span/group
       *
       * @property colspan
       * @type number
       */
      colspan: Number,
      /**
       * If set to true, visually hides all footers in the Grid
       *
       * @property hidden
       * @type boolean
       */
      hidden: Boolean
    },
    /**
     * Adds a new footer row.
     *
     * @method addRow
     * @param {number} index The position where to insert the new footer row. If undefined, it is insert as the last row.
     */
    addRow: function(index) {},
    /**
     * Removes a specific footer row.
     *
     * @method removeRow
     * @param {number} index The row index to remove.
     */
    removeRow: function(index) {},
    /**
     * Returns an object reference to a particular footer cell.
     *
     * @method getCell
     * @param {number} rowIndex The row index.
     * @param {number|string} column The column.
     * @return {StaticCell} An object reference to a particular footer cell
     */
    getCell: function(rowIndex, column) {}
  });
</script>

<!--
Object for manipulating header rows
-->
<dom-module id="Header"></dom-module>
<script>
  Polymer({
    is: 'Header',
    properties: {
      /**
       * The number of columns which this cell should span/group
       *
       * @property colspan
       * @type number
       */
      colspan: Number,
      /**
       * If set to true, visually hides all headers in the Grid
       *
       * @property hidden
       * @type boolean
       */
      hidden: Boolean,
      /**
       * Sets the index of the default header row in the headers array
       *
       * @property defaultRow
       * @type number
       */
      defaultRow: Number
    },
    /**
     * Adds a new header row.
     *
     * @method addRow
     * @param {number} index The position where to insert the new header row. If undefined, it is insert as the last row.
     */
    addRow: function(index) {},
    /**
     * Removes a specific header row.
     *
     * @method removeRow
     * @param {number} index The row index to remove.
     */
    removeRow: function(index) {},
    /**
     * Returns an object reference to a particular header cell.
     *
     * @method getCell
     * @param {number} rowIndex The row index.
     * @param {number|string} column The column.
     * @return {StaticCell} An object reference to a particular header cell
     */
    getCell: function(rowIndex, column) {}
  });
</script>

<!--
Represents a grid header/footer row configuration.
-->
<dom-module id="StaticCell"></dom-module>
<script>
  Polymer({
    is: 'Row',
    properties: {
      /**
       * The row index
       */
      index:  Number,
      /**
       * The row data object from the data source
       *
       * @property data
       * @type {*}
       */
      data:  Object,
      /**
       * Reference to the &lt;table is=v-grid> element
       *
       * @property grid
       * @type {HTMLElement}
       */
      grid:  Object,
      /**
       * Reference to the TR element
       *
       * @property element
       * @type {HTMLElement}
       */
      element:  Object
    }
  });
</script>

<!--
The Object used for configuring the selection model of the grid.
-->
<dom-module id="Selection"></dom-module>
<script>
  Polymer({
    is: 'Selection',
    properties: {
      /**
       * The mode
       *
       * @property mode
       * @type {"single"|"multi"|"all"|"disabled"}
       */
      mode: String,
      /**
       * The size
       */
      size: Number
    },
    /**
     * Selects certain row
     *
     * @method select
     * @param {number} index – The row index
     */
    select: function(index) {},
    /**
     * Deselects certain row
     *
     * @method deselect
     * @param {number} index – The row index
     */
    deselect: function(index) {},
    /**
     * Clears selection
     *
     * @method clear
     */
    clear: function() {},
    /**
     * Selects all rows
     *
     * @method selectAll
     */
    selectAll: function() {},
    /**
     * Gets selected row indexes
     *
     * @method selected
     * @return {Array<Number>} The selected row indexes
     */
    selected: function() {},
    /**
     * Gets deselected row indexes
     *
     * @method deselected
     * @return {Array<Number>} The deselected row indexes
     */
    deselected: function() {}
  });
</script>

<!--
Represents the sort configuration of a column.
-->
<dom-module id="SortOrder"></dom-module>
<script>
  Polymer({
    is: 'SortOrder',
    properties: {
      /**
       * The sort direction
       * 
       * @property direction
       * @type {"asc"|"desc"}
       */
      direction:  String,
      /**
       * The index of column
       */
      column:  Number
    }
  });
</script>

<!--
Represents a grid header/footer cell configuration.
-->
<dom-module id="StaticCell"></dom-module>
<script>
  Polymer({
    is: 'StaticCell',
    properties: {
      /**
       * The class name
       */
      className:  String,
      /**
       * The number of columns which this cell should span/group
       */
      colspan:  Number
    }
  });
</script>