|
483 | 483 | }
|
484 | 484 |
|
485 | 485 | var cellNavNavigateDereg = function() {};
|
| 486 | + var viewPortKeyDownDereg = function() {}; |
486 | 487 |
|
487 |
| - // Bind to keydown events in the render container |
488 |
| - if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) { |
489 |
| - |
490 |
| - uiGridCtrl.grid.api.cellNav.on.viewPortKeyDown($scope, function (evt, rowCol) { |
491 |
| - if (rowCol === null) { |
492 |
| - return; |
493 |
| - } |
494 |
| - |
495 |
| - if (rowCol.row === $scope.row && rowCol.col === $scope.col && !$scope.col.colDef.enableCellEditOnFocus) { |
496 |
| - //important to do this before scrollToIfNecessary |
497 |
| - beginEditKeyDown(evt); |
498 |
| - // uiGridCtrl.grid.api.core.scrollToIfNecessary(rowCol.row, rowCol.col); |
499 |
| - } |
500 |
| - |
501 |
| - }); |
502 |
| - } |
503 | 488 |
|
504 | 489 | var setEditable = function() {
|
505 | 490 | if ($scope.col.colDef.enableCellEdit && $scope.row.enableCellEdit !== false) {
|
506 |
| - registerBeginEditEvents(); |
| 491 | + if (!$scope.beginEditEventsWired) { //prevent multiple attachments |
| 492 | + registerBeginEditEvents(); |
| 493 | + } |
507 | 494 | } else {
|
508 |
| - cancelBeginEditEvents(); |
| 495 | + if ($scope.beginEditEventsWired) { |
| 496 | + cancelBeginEditEvents(); |
| 497 | + } |
509 | 498 | }
|
510 | 499 | };
|
511 | 500 |
|
512 | 501 | setEditable();
|
513 | 502 |
|
514 |
| - var rowWatchDereg = $scope.$watch( 'row', setEditable ); |
| 503 | + var rowWatchDereg = $scope.$watch('row', function (n, o) { |
| 504 | + if (n !== o) { |
| 505 | + setEditable(); |
| 506 | + } |
| 507 | + }); |
| 508 | + |
| 509 | + |
515 | 510 | $scope.$on( '$destroy', rowWatchDereg );
|
516 | 511 |
|
517 | 512 | function registerBeginEditEvents() {
|
|
521 | 516 | $elm.on('touchstart', touchStart);
|
522 | 517 |
|
523 | 518 | if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
|
| 519 | + |
| 520 | + viewPortKeyDownDereg = uiGridCtrl.grid.api.cellNav.on.viewPortKeyDown($scope, function (evt, rowCol) { |
| 521 | + if (rowCol === null) { |
| 522 | + return; |
| 523 | + } |
| 524 | + |
| 525 | + if (rowCol.row === $scope.row && rowCol.col === $scope.col && !$scope.col.colDef.enableCellEditOnFocus) { |
| 526 | + //important to do this before scrollToIfNecessary |
| 527 | + beginEditKeyDown(evt); |
| 528 | + } |
| 529 | + }); |
| 530 | + |
524 | 531 | cellNavNavigateDereg = uiGridCtrl.grid.api.cellNav.on.navigate($scope, function (newRowCol, oldRowCol) {
|
525 | 532 | if ($scope.col.colDef.enableCellEditOnFocus) {
|
526 | 533 | if (newRowCol.row === $scope.row && newRowCol.col === $scope.col) {
|
|
532 | 539 | });
|
533 | 540 | }
|
534 | 541 |
|
535 |
| - |
| 542 | + $scope.beginEditEventsWired = true; |
536 | 543 |
|
537 | 544 | }
|
538 | 545 |
|
|
569 | 576 | $elm.off('keydown', beginEditKeyDown);
|
570 | 577 | $elm.off('touchstart', touchStart);
|
571 | 578 | cellNavNavigateDereg();
|
| 579 | + viewPortKeyDownDereg(); |
| 580 | + $scope.beginEditEventsWired = false; |
572 | 581 | }
|
573 | 582 |
|
574 | 583 | function beginEditKeyDown(evt) {
|
|
0 commit comments