|
28 | 28 | }); |
29 | 29 |
|
30 | 30 | //add methods to GridRow |
31 | | - angular.module('ui.grid').config(['$provide', function($provide) { |
32 | | - $provide.decorator('GridRow', ['$delegate', function($delegate) { |
| 31 | + angular.module('ui.grid').config(['$provide', function ($provide) { |
| 32 | + $provide.decorator('GridRow', ['$delegate', function ($delegate) { |
33 | 33 |
|
34 | 34 | /** |
35 | 35 | * @ngdoc object |
|
57 | 57 | */ |
58 | 58 |
|
59 | 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} selected value to set |
67 | | - */ |
68 | | - $delegate.prototype.setSelected = function(selected) { |
69 | | - if (selected !== this.isSelected) { |
70 | | - this.isSelected = selected; |
71 | | - this.grid.selection.selectedCount += selected ? 1 : -1; |
72 | | - } |
73 | | - }; |
| 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} selected value to set |
| 67 | + */ |
| 68 | + $delegate.prototype.setSelected = function (selected) { |
| 69 | + if (selected !== this.isSelected) { |
| 70 | + this.isSelected = selected; |
| 71 | + this.grid.selection.selectedCount += selected ? 1 : -1; |
| 72 | + } |
| 73 | + }; |
74 | 74 |
|
75 | 75 | return $delegate; |
76 | 76 | }]); |
|
188 | 188 | * @param {number} index index within the rowsVisible array |
189 | 189 | * @param {Event} event object if raised from an event |
190 | 190 | */ |
191 | | - selectRowByVisibleIndex: function ( rowNum, evt ) { |
| 191 | + selectRowByVisibleIndex: function (rowNum, evt) { |
192 | 192 | var row = grid.renderContainers.body.visibleRowCache[rowNum]; |
193 | | - if (row !== null && typeof(row) !== 'undefined' && !row.isSelected) { |
| 193 | + if (row !== null && typeof (row) !== 'undefined' && !row.isSelected) { |
194 | 194 | service.toggleRowSelection(grid, row, evt, grid.options.multiSelect, grid.options.noUnselect); |
195 | 195 | } |
196 | 196 | }, |
|
222 | 222 |
|
223 | 223 | var changedRows = []; |
224 | 224 | grid.rows.forEach(function (row) { |
225 | | - if ( !row.isSelected && row.enableSelection !== false ){ |
| 225 | + if (!row.isSelected && row.enableSelection !== false) { |
226 | 226 | row.setSelected(true); |
227 | | - service.decideRaiseSelectionEvent( grid, row, changedRows, evt ); |
| 227 | + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); |
228 | 228 | } |
229 | 229 | }); |
230 | | - service.decideRaiseSelectionBatchEvent( grid, changedRows, evt ); |
| 230 | + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); |
231 | 231 | grid.selection.selectAll = true; |
232 | 232 | }, |
233 | 233 | /** |
|
245 | 245 | var changedRows = []; |
246 | 246 | grid.rows.forEach(function (row) { |
247 | 247 | if (row.visible) { |
248 | | - if (!row.isSelected && row.enableSelection !== false){ |
| 248 | + if (!row.isSelected && row.enableSelection !== false) { |
249 | 249 | row.setSelected(true); |
250 | | - service.decideRaiseSelectionEvent( grid, row, changedRows, evt ); |
| 250 | + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); |
251 | 251 | } |
252 | 252 | } else { |
253 | | - if (row.isSelected){ |
| 253 | + if (row.isSelected) { |
254 | 254 | row.setSelected(false); |
255 | | - service.decideRaiseSelectionEvent( grid, row, changedRows, evt ); |
| 255 | + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); |
256 | 256 | } |
257 | 257 | } |
258 | 258 | }); |
259 | | - service.decideRaiseSelectionBatchEvent( grid, changedRows, evt ); |
| 259 | + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); |
260 | 260 | grid.selection.selectAll = true; |
261 | 261 | }, |
262 | 262 | /** |
|
401 | 401 | * @description Enable selection by clicking anywhere on the row. Defaults to |
402 | 402 | * false if `enableRowHeaderSelection` is true, otherwise defaults to false. |
403 | 403 | */ |
404 | | - if ( typeof(gridOptions.enableFullRowSelection) === 'undefined' ){ |
| 404 | + if (typeof (gridOptions.enableFullRowSelection) === 'undefined') { |
405 | 405 | gridOptions.enableFullRowSelection = !gridOptions.enableRowHeaderSelection; |
406 | 406 | } |
407 | 407 | /** |
|
466 | 466 | toggleRowSelection: function (grid, row, evt, multiSelect, noUnselect) { |
467 | 467 | var selected = row.isSelected; |
468 | 468 |
|
469 | | - if ( row.enableSelection === false && !selected ){ |
| 469 | + if (row.enableSelection === false && !selected) { |
470 | 470 | return; |
471 | 471 | } |
472 | 472 |
|
|
481 | 481 | } |
482 | 482 | } |
483 | 483 |
|
484 | | - if (selected && noUnselect){ |
| 484 | + if (selected && noUnselect) { |
485 | 485 | // don't deselect the row |
486 | 486 | } else { |
487 | 487 | row.setSelected(!selected); |
|
523 | 523 | for (var i = fromRow; i <= toRow; i++) { |
524 | 524 | var rowToSelect = grid.renderContainers.body.visibleRowCache[i]; |
525 | 525 | if (rowToSelect) { |
526 | | - if ( !rowToSelect.isSelected && rowToSelect.enableSelection !== false ){ |
| 526 | + if (!rowToSelect.isSelected && rowToSelect.enableSelection !== false) { |
527 | 527 | rowToSelect.setSelected(true); |
528 | 528 | grid.selection.lastSelectedRow = rowToSelect; |
529 | | - service.decideRaiseSelectionEvent( grid, rowToSelect, changedRows, evt ); |
| 529 | + service.decideRaiseSelectionEvent(grid, rowToSelect, changedRows, evt); |
530 | 530 | } |
531 | 531 | } |
532 | 532 | } |
533 | | - service.decideRaiseSelectionBatchEvent( grid, changedRows, evt ); |
| 533 | + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); |
534 | 534 | }, |
535 | 535 | /** |
536 | 536 | * @ngdoc function |
|
556 | 556 | clearSelectedRows: function (grid, evt) { |
557 | 557 | var changedRows = []; |
558 | 558 | service.getSelectedRows(grid).forEach(function (row) { |
559 | | - if ( row.isSelected ){ |
| 559 | + if (row.isSelected) { |
560 | 560 | row.setSelected(false); |
561 | | - service.decideRaiseSelectionEvent( grid, row, changedRows, evt ); |
| 561 | + service.decideRaiseSelectionEvent(grid, row, changedRows, evt); |
562 | 562 | } |
563 | 563 | }); |
564 | | - service.decideRaiseSelectionBatchEvent( grid, changedRows, evt ); |
| 564 | + service.decideRaiseSelectionBatchEvent(grid, changedRows, evt); |
565 | 565 | grid.selection.selectAll = false; |
566 | 566 | grid.selection.selectedCount = 0; |
567 | 567 | }, |
|
577 | 577 | * @param {Event} event object if raised from an event |
578 | 578 | * row if we're doing batch events |
579 | 579 | */ |
580 | | - decideRaiseSelectionEvent: function( grid, row, changedRows, evt ){ |
581 | | - if ( !grid.options.enableSelectionBatchEvent ){ |
| 580 | + decideRaiseSelectionEvent: function (grid, row, changedRows, evt) { |
| 581 | + if (!grid.options.enableSelectionBatchEvent) { |
582 | 582 | grid.api.selection.raise.rowSelectionChanged(row, evt); |
583 | 583 | } else { |
584 | 584 | changedRows.push(row); |
|
596 | 596 | * @param {Event} event object if raised from an event |
597 | 597 | * if we're doing batch events |
598 | 598 | */ |
599 | | - decideRaiseSelectionBatchEvent: function( grid, changedRows, evt ){ |
600 | | - if ( changedRows.length > 0 ){ |
| 599 | + decideRaiseSelectionBatchEvent: function (grid, changedRows, evt) { |
| 600 | + if (changedRows.length > 0) { |
601 | 601 | grid.api.selection.raise.rowSelectionChangedBatch(changedRows, evt); |
602 | 602 | } |
603 | 603 | } |
|
654 | 654 | var selectionRowHeaderDef = { |
655 | 655 | name: uiGridSelectionConstants.selectionRowHeaderColName, |
656 | 656 | displayName: '', |
657 | | - width: uiGridCtrl.grid.options.selectionRowHeaderWidth, |
| 657 | + width: uiGridCtrl.grid.options.selectionRowHeaderWidth, |
658 | 658 | minWidth: 10, |
659 | 659 | cellTemplate: 'ui-grid/selectionRowHeader', |
660 | 660 | headerCellTemplate: 'ui-grid/selectionHeaderCell', |
|
669 | 669 |
|
670 | 670 | var processorSet = false; |
671 | 671 |
|
672 | | - var processSelectableRows = function( rows ){ |
673 | | - rows.forEach(function(row){ |
| 672 | + var processSelectableRows = function (rows) { |
| 673 | + rows.forEach(function (row) { |
674 | 674 | row.enableSelection = uiGridCtrl.grid.options.isRowSelectable(row); |
675 | 675 | }); |
676 | 676 | return rows; |
677 | 677 | }; |
678 | 678 |
|
679 | | - var updateOptions = function(){ |
| 679 | + var updateOptions = function () { |
680 | 680 | if (uiGridCtrl.grid.options.isRowSelectable !== angular.noop && processorSet !== true) { |
681 | 681 | uiGridCtrl.grid.registerRowsProcessor(processSelectableRows, 500); |
682 | 682 | processorSet = true; |
|
685 | 685 |
|
686 | 686 | updateOptions(); |
687 | 687 |
|
688 | | - var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback( updateOptions, [uiGridConstants.dataChange.OPTIONS] ); |
| 688 | + var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(updateOptions, [uiGridConstants.dataChange.OPTIONS]); |
689 | 689 |
|
690 | | - $scope.$on( '$destroy', dataChangeDereg); |
| 690 | + $scope.$on('$destroy', dataChangeDereg); |
691 | 691 | }, |
692 | 692 | post: function ($scope, $elm, $attrs, uiGridCtrl) { |
693 | 693 |
|
|
705 | 705 | template: $templateCache.get('ui-grid/selectionRowHeaderButtons'), |
706 | 706 | scope: true, |
707 | 707 | require: '^uiGrid', |
708 | | - link: function($scope, $elm, $attrs, uiGridCtrl) { |
| 708 | + link: function ($scope, $elm, $attrs, uiGridCtrl) { |
709 | 709 | var self = uiGridCtrl.grid; |
710 | 710 | $scope.selectButtonClick = selectButtonClick; |
711 | 711 |
|
|
725 | 725 | else if (evt.ctrlKey || evt.metaKey) { |
726 | 726 | uiGridSelectionService.toggleRowSelection(self, row, evt, self.options.multiSelect, self.options.noUnselect); |
727 | 727 | } |
| 728 | + else if (row.groupHeader) { |
| 729 | + for (var i = 0; i < row.treeNode.children.length; i++) { |
| 730 | + uiGridSelectionService.toggleRowSelection(self, row.treeNode.children[i].row, evt, self.options.multiSelect, self.options.noUnselect); |
| 731 | + } |
| 732 | + } |
728 | 733 | else { |
729 | 734 | uiGridSelectionService.toggleRowSelection(self, row, evt, (self.options.multiSelect && !self.options.modifierKeysToMultiSelect), self.options.noUnselect); |
730 | 735 | } |
|
751 | 756 | restrict: 'E', |
752 | 757 | template: $templateCache.get('ui-grid/selectionSelectAllButtons'), |
753 | 758 | scope: false, |
754 | | - link: function($scope, $elm, $attrs, uiGridCtrl) { |
| 759 | + link: function ($scope, $elm, $attrs, uiGridCtrl) { |
755 | 760 | var self = $scope.col.grid; |
756 | 761 |
|
757 | | - $scope.headerButtonClick = function(row, evt) { |
758 | | - if ( self.selection.selectAll ){ |
| 762 | + $scope.headerButtonClick = function (row, evt) { |
| 763 | + if (self.selection.selectAll) { |
759 | 764 | uiGridSelectionService.clearSelectedRows(self, evt); |
760 | | - if ( self.options.noUnselect ){ |
| 765 | + if (self.options.noUnselect) { |
761 | 766 | self.api.selection.selectRowByVisibleIndex(0, evt); |
762 | 767 | } |
763 | 768 | self.selection.selectAll = false; |
764 | 769 | } else { |
765 | | - if ( self.options.multiSelect ){ |
| 770 | + if (self.options.multiSelect) { |
766 | 771 | self.api.selection.selectAllVisibleRows(evt); |
767 | 772 | self.selection.selectAll = true; |
768 | 773 | } |
|
791 | 796 |
|
792 | 797 | var existingNgClass = rowRepeatDiv.attr("ng-class"); |
793 | 798 | var newNgClass = ''; |
794 | | - if ( existingNgClass ) { |
| 799 | + if (existingNgClass) { |
795 | 800 | newNgClass = existingNgClass.slice(0, -1) + ",'ui-grid-row-selected': row.isSelected}"; |
796 | 801 | } else { |
797 | 802 | newNgClass = "{'ui-grid-row-selected': row.isSelected}"; |
|
845 | 850 | $scope.$apply(); |
846 | 851 | } |
847 | 852 |
|
848 | | - // uiGridCellNavService.scrollToIfNecessary(uiGridCtrl.grid, rowCol.row, rowCol.col); |
| 853 | + // uiGridCellNavService.scrollToIfNecessary(uiGridCtrl.grid, rowCol.row, rowCol.col); |
849 | 854 | }); |
850 | 855 | } |
851 | 856 |
|
|
856 | 861 | // } |
857 | 862 | //}); |
858 | 863 |
|
859 | | - var selectCells = function(evt){ |
| 864 | + var selectCells = function (evt) { |
860 | 865 | // if you click on expandable icon doesn't trigger selection |
861 | 866 | if (evt.target.className === "ui-grid-icon-minus-squared" || evt.target.className === "ui-grid-icon-plus-squared") { |
862 | 867 | return; |
|
878 | 883 |
|
879 | 884 | // don't re-enable the touchend handler for a little while - some devices generate both, and it will |
880 | 885 | // take a little while to move your hand from the mouse to the screen if you have both modes of input |
881 | | - $timeout(function() { |
| 886 | + $timeout(function () { |
882 | 887 | $elm.on('touchend', touchEnd); |
883 | 888 | }, touchTimeout); |
884 | 889 | }; |
885 | 890 |
|
886 | | - var touchStart = function(evt){ |
| 891 | + var touchStart = function (evt) { |
887 | 892 | touchStartTime = (new Date()).getTime(); |
888 | 893 |
|
889 | 894 | // if we get a touch event, then stop listening for click |
890 | 895 | $elm.off('click', selectCells); |
891 | 896 | }; |
892 | 897 |
|
893 | | - var touchEnd = function(evt) { |
| 898 | + var touchEnd = function (evt) { |
894 | 899 | var touchEndTime = (new Date()).getTime(); |
895 | 900 | var touchTime = touchEndTime - touchStartTime; |
896 | 901 |
|
897 | | - if (touchTime < touchTimeout ) { |
| 902 | + if (touchTime < touchTimeout) { |
898 | 903 | // short touch |
899 | 904 | selectCells(evt); |
900 | 905 | } |
901 | 906 |
|
902 | 907 | // don't re-enable the click handler for a little while - some devices generate both, and it will |
903 | 908 | // take a little while to move your hand from the screen to the mouse if you have both modes of input |
904 | | - $timeout(function() { |
| 909 | + $timeout(function () { |
905 | 910 | $elm.on('click', selectCells); |
906 | 911 | }, touchTimeout); |
907 | 912 | }; |
|
918 | 923 | } |
919 | 924 |
|
920 | 925 | function deregisterRowSelectionEvents() { |
921 | | - if ($scope.registered){ |
| 926 | + if ($scope.registered) { |
922 | 927 | $elm.removeClass('ui-grid-disable-selection'); |
923 | 928 |
|
924 | 929 | $elm.off('touchstart', touchStart); |
|
932 | 937 | registerRowSelectionEvents(); |
933 | 938 | // register a dataChange callback so that we can change the selection configuration dynamically |
934 | 939 | // if the user changes the options |
935 | | - var dataChangeDereg = $scope.grid.registerDataChangeCallback( function() { |
936 | | - if ( $scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection && |
937 | | - !$scope.registered ){ |
| 940 | + var dataChangeDereg = $scope.grid.registerDataChangeCallback(function () { |
| 941 | + if ($scope.grid.options.enableRowSelection && $scope.grid.options.enableFullRowSelection && |
| 942 | + !$scope.registered) { |
938 | 943 | registerRowSelectionEvents(); |
939 | | - } else if ( ( !$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection ) && |
940 | | - $scope.registered ){ |
| 944 | + } else if ((!$scope.grid.options.enableRowSelection || !$scope.grid.options.enableFullRowSelection) && |
| 945 | + $scope.registered) { |
941 | 946 | deregisterRowSelectionEvents(); |
942 | 947 | } |
943 | | - }, [uiGridConstants.dataChange.OPTIONS] ); |
| 948 | + }, [uiGridConstants.dataChange.OPTIONS]); |
944 | 949 |
|
945 | | - $elm.on( '$destroy', dataChangeDereg); |
| 950 | + $elm.on('$destroy', dataChangeDereg); |
946 | 951 | } |
947 | 952 | }; |
948 | 953 | }]); |
|
0 commit comments