|
27 | 27 | selectionRowHeaderColName: 'selectionRowHeaderCol'
|
28 | 28 | });
|
29 | 29 |
|
| 30 | + //add methods to GridRow |
| 31 | + angular.module('ui.grid').config(['$provide', function($provide) { |
| 32 | + $provide.decorator('GridRow', ['$delegate', function($delegate) { |
| 33 | + |
| 34 | + /** |
| 35 | + * @ngdoc object |
| 36 | + * @name ui.grid.selection.api:GridRow |
| 37 | + * |
| 38 | + * @description GridRow prototype functions added for selection |
| 39 | + */ |
| 40 | + |
| 41 | + /** |
| 42 | + * @ngdoc object |
| 43 | + * @name enableSelection |
| 44 | + * @propertyOf ui.grid.selection.api:GridRow |
| 45 | + * @description Enable row selection for this row, only settable by internal code. |
| 46 | + * |
| 47 | + * The grouping feature, for example, might set group header rows to not be selectable. |
| 48 | + * <br/>Defaults to true |
| 49 | + */ |
| 50 | + |
| 51 | + /** |
| 52 | + * @ngdoc object |
| 53 | + * @name isSelected |
| 54 | + * @propertyOf ui.grid.selection.api:GridRow |
| 55 | + * @description Selected state of row. Should be readonly. Make any changes to selected state using setSelected(). |
| 56 | + * <br/>Defaults to false |
| 57 | + */ |
| 58 | + |
| 59 | + |
| 60 | + /** |
| 61 | + * @ngdoc function |
| 62 | + * @name setSelected |
| 63 | + * @methodOf ui.grid.selection.api:GridRow |
| 64 | + * @description Sets the isSelected property and updates the selectedCount |
| 65 | + * Changes to isSelected state should only be made via this function |
| 66 | + * @param {bool} selelected value to set |
| 67 | + */ |
| 68 | + $delegate.prototype.setSelected = function(selected) { |
| 69 | + this.isSelected = selected; |
| 70 | + if (selected) { |
| 71 | + this.grid.selection.selectedCount++; |
| 72 | + } |
| 73 | + else { |
| 74 | + this.grid.selection.selectedCount--; |
| 75 | + } |
| 76 | + }; |
| 77 | + |
| 78 | + return $delegate; |
| 79 | + }]); |
| 80 | + }]); |
| 81 | + |
30 | 82 | /**
|
31 | 83 | * @ngdoc service
|
32 | 84 | * @name ui.grid.selection.service:uiGridSelectionService
|
|
40 | 92 |
|
41 | 93 | initializeGrid: function (grid) {
|
42 | 94 |
|
43 |
| - //add feature namespace and any properties to grid for needed state |
| 95 | + //add feature namespace and any properties to grid for needed |
| 96 | + /** |
| 97 | + * @ngdoc object |
| 98 | + * @name ui.grid.selection.grid:selection |
| 99 | + * |
| 100 | + * @description Grid properties and functions added for selection |
| 101 | + */ |
44 | 102 | grid.selection = {};
|
45 | 103 | grid.selection.lastSelectedRow = null;
|
46 | 104 | grid.selection.selectAll = false;
|
47 | 105 |
|
| 106 | + |
| 107 | + /** |
| 108 | + * @ngdoc object |
| 109 | + * @name selectedCount |
| 110 | + * @propertyOf ui.grid.selection.grid:selection |
| 111 | + * @description Current count of selected rows |
| 112 | + * @example |
| 113 | + * var count = grid.selection.selectedCount |
| 114 | + */ |
| 115 | + grid.selection.selectedCount = 0; |
| 116 | + |
48 | 117 | service.defaultGridOptions(grid.options);
|
49 | 118 |
|
50 | 119 | /**
|
|
157 | 226 | var changedRows = [];
|
158 | 227 | grid.rows.forEach(function (row) {
|
159 | 228 | if ( !row.isSelected && row.enableSelection !== false ){
|
160 |
| - row.isSelected = true; |
| 229 | + row.setSelected(true); |
161 | 230 | service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
|
162 | 231 | }
|
163 | 232 | });
|
|
180 | 249 | grid.rows.forEach(function (row) {
|
181 | 250 | if (row.visible) {
|
182 | 251 | if (!row.isSelected && row.enableSelection !== false){
|
183 |
| - row.isSelected = true; |
| 252 | + row.setSelected(true); |
184 | 253 | service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
|
185 | 254 | }
|
186 | 255 | } else {
|
187 | 256 | if (row.isSelected){
|
188 |
| - row.isSelected = false; |
| 257 | + row.setSelected(false); |
189 | 258 | service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
|
190 | 259 | }
|
191 | 260 | }
|
|
276 | 345 | * set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
|
277 | 346 | */
|
278 | 347 |
|
279 |
| - /** |
280 |
| - * @ngdoc object |
281 |
| - * @name ui.grid.selection.api:GridRow |
282 |
| - * |
283 |
| - * @description GridRow options for selection feature |
284 |
| - */ |
285 |
| - /** |
286 |
| - * @ngdoc object |
287 |
| - * @name enableSelection |
288 |
| - * @propertyOf ui.grid.selection.api:GridRow |
289 |
| - * @description Enable row selection for this row, only settable by internal code. |
290 |
| - * |
291 |
| - * The grouping feature, for example, might set group header rows to not be selectable. |
292 |
| - * <br/>Defaults to true |
293 |
| - */ |
294 |
| - |
295 |
| - |
296 | 348 | /**
|
297 | 349 | * @ngdoc object
|
298 | 350 | * @name enableRowSelection
|
|
363 | 415 | * <br/>Defaults to 30px
|
364 | 416 | */
|
365 | 417 | gridOptions.selectionRowHeaderWidth = angular.isDefined(gridOptions.selectionRowHeaderWidth) ? gridOptions.selectionRowHeaderWidth : 30;
|
| 418 | + |
| 419 | + /** |
| 420 | + * @ngdoc object |
| 421 | + * @name enableFooterTotalSelected |
| 422 | + * @propertyOf ui.grid.selection.api:GridOptions |
| 423 | + * @description Shows the total number of selected items in footer if true. |
| 424 | + * <br/>Defaults to true. |
| 425 | + * <br/>GridOptions.showFooter must also be set to true. |
| 426 | + */ |
| 427 | + gridOptions.enableFooterTotalSelected = gridOptions.enableFooterTotalSelected !== false; |
366 | 428 | },
|
367 | 429 |
|
368 | 430 | /**
|
|
392 | 454 | if (selected && noUnselect){
|
393 | 455 | // don't deselect the row
|
394 | 456 | } else if (row.enableSelection !== false) {
|
395 |
| - row.isSelected = !selected; |
| 457 | + row.setSelected(!selected); |
396 | 458 | if (row.isSelected === true) {
|
397 | 459 | grid.selection.lastSelectedRow = row;
|
398 | 460 | } else {
|
|
430 | 492 | var rowToSelect = grid.renderContainers.body.visibleRowCache[i];
|
431 | 493 | if (rowToSelect) {
|
432 | 494 | if ( !rowToSelect.isSelected && rowToSelect.enableSelection !== false ){
|
433 |
| - rowToSelect.isSelected = true; |
| 495 | + rowToSelect.setSelected(true); |
434 | 496 | grid.selection.lastSelectedRow = rowToSelect;
|
435 | 497 | service.decideRaiseSelectionEvent( grid, rowToSelect, changedRows, evt );
|
436 | 498 | }
|
|
463 | 525 | var changedRows = [];
|
464 | 526 | service.getSelectedRows(grid).forEach(function (row) {
|
465 | 527 | if ( row.isSelected ){
|
466 |
| - row.isSelected = false; |
| 528 | + row.setSelected(false); |
467 | 529 | service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
|
468 | 530 | }
|
469 | 531 | });
|
|
757 | 819 | };
|
758 | 820 | }]);
|
759 | 821 |
|
| 822 | + module.directive('uiGridGridFooter', ['$compile', 'uiGridConstants', 'gridUtil', function ($compile, uiGridConstants, gridUtil) { |
| 823 | + return { |
| 824 | + restrict: 'EA', |
| 825 | + replace: true, |
| 826 | + priority: -1000, |
| 827 | + require: '^uiGrid', |
| 828 | + scope: true, |
| 829 | + compile: function ($elm, $attrs) { |
| 830 | + return { |
| 831 | + pre: function ($scope, $elm, $attrs, uiGridCtrl) { |
| 832 | + |
| 833 | + if (!uiGridCtrl.grid.options.showGridFooter) { |
| 834 | + return; |
| 835 | + } |
| 836 | + |
| 837 | + |
| 838 | + gridUtil.getTemplate('ui-grid/gridFooterSelectedItems') |
| 839 | + .then(function (contents) { |
| 840 | + var template = angular.element(contents); |
| 841 | + |
| 842 | + var newElm = $compile(template)($scope); |
| 843 | + |
| 844 | + angular.element($elm[0].getElementsByClassName('ui-grid-grid-footer')[0]).append(newElm); |
| 845 | + }); |
| 846 | + }, |
| 847 | + |
| 848 | + post: function ($scope, $elm, $attrs, controllers) { |
| 849 | + |
| 850 | + } |
| 851 | + }; |
| 852 | + } |
| 853 | + }; |
| 854 | + }]); |
| 855 | + |
760 | 856 | })();
|
0 commit comments