ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

multiselect on row causing handleKeyDown error

Open yleigh opened this issue 11 years ago • 5 comments

I'm using a second ui-grid table in modal dialog. I followed the 'selection' example to allow multiSelect. Here's my setup: $scope.gridOptionNodes = { enabledColumnResize: true, enableRowSelection: true, enableRowHeaderSelection: false, multiSelect: true, modifierKeysToMultiSelect: true, enableHighlighting: false };

But when I use Ctrl or Shift for multi-select rows, Chrome debugger gives me error: Uncaught TypeError: Cannot read property 'handleKeyDown' of undefined (ui-grid.js:11412)

I'm using rc-16 build. The source code as: // Bind to keydown events in the render container $elm.on('keydown', function (evt) { evt.uiGridTargetRenderContainerId = containerId; return uiGridCtrl.cellNav.handleKeyDown(evt); });

Do I have to disable multiSelect? How could I get rid of this error? Or is it because I'm using the wrong build?

Thanks

yleigh avatar Dec 09 '14 16:12 yleigh

I am not aware of things changing in this area recently, so I doubt it's a wrong build.

Any chance of a short plunker demonstrating the issue? It sounds like the cell doesn't exist for some reason, but not sure why. Does it do it on the tutorial for the selection feature?

PaulL1 avatar Dec 10 '14 07:12 PaulL1

Sorry for delay. I'm trying to use the data I just created plunker for it, same code, but it works fine. Although I have another table on my non-modal page. Wonder if some conflict:

http://plnkr.co/edit/D8btFH4eG5M0bIQkSNCY

yleigh avatar Dec 12 '14 22:12 yleigh

In my browser debugger that has the error, it's caused from jquery and end up in ui-grid: module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants', function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants) { return { replace: true, priority: -99999, //this needs to run very last require: ['^uiGrid', 'uiGridRenderContainer'], scope: false, compile: function () { return { pre: function ($scope, $elm, $attrs, uiGridCtrl) { }, post: function ($scope, $elm, $attrs, controllers) { var uiGridCtrl = controllers[0], renderContainerCtrl = controllers[1];

          var containerId = renderContainerCtrl.containerId;

          var grid = uiGridCtrl.grid;

          // Needs to run last after all renderContainers are built
          uiGridCellNavService.decorateRenderContainers(grid);

          // Let the render container be focus-able
          $elm.attr("tabindex", -1);

          // Bind to keydown events in the render container
          $elm.on('keydown', function (evt) {
            evt.uiGridTargetRenderContainerId = containerId;
            return uiGridCtrl.cellNav.handleKeyDown(evt);
          });

This "uiGridCtrl.cellNav" is undefined. And it's an JQuery event: 3 characters selected

Pause On Caught Exceptions

Watch Expressions uiGridCtrl: $get.Constructor uiGridCtrl.cellNav: undefined controllers: evt: jQuery.Event altKey: false bubbles: true cancelable: true char: undefined charCode: 0 ctrlKey: false currentTarget: div.ui-grid-render-container.ng-isolate-scope.ui-grid-render-container-body data: undefined delegateTarget: div.ui-grid-render-container.ng-isolate-scope.ui-grid-render-container-body eventPhase: 2 handleObj: Object isDefaultPrevented: function returnFalse() { jQuery21004913958127144724: true key: undefined keyCode: 16 metaKey: false originalEvent: KeyboardEvent altKey: false bubbles: true cancelBubble: false cancelable: true charCode: 0 clipboardData: undefined ctrlKey: false currentTarget: div.ui-grid-render-container.ng-isolate-scope.ui-grid-render-container-body defaultPrevented: false detail: 0 eventPhase: 2 keyCode: 16 keyIdentifier: "Shift" keyLocation: 1 layerX: 0 layerY: 0 location: 1 metaKey: false pageX: 0 pageY: 0 path: NodeList[9] repeat: false returnValue: true shiftKey: true srcElement: div.ui-grid-render-container.ng-isolate-scope.ui-grid-render-container-body target: div.ui-grid-render-container.ng-isolate-scope.ui-grid-render-container-body timeStamp: 1418443051856 type: "keydown" view: Window which: 16 proto: KeyboardEvent relatedTarget: undefined shiftKey: true target: div.ui-grid-render-container.ng-isolate-scope.ui-grid-render-container-body timeStamp: 1418443051856 type: "keydown" uiGridTargetRenderContainerId: "body" view: Window which: 16 proto: Object

Is there a way I can disable jQuery handle 'keydown' event? Thanks.

yleigh avatar Dec 13 '14 04:12 yleigh

OK. I found the difference between rc-16 ui-grid.js and current unstable ui-grid: module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants', function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants) { return { replace: true, priority: -99999, //this needs to run very last require: ['^uiGrid', 'uiGridRenderContainer', '?^uiGridCellnav'], scope: false, compile: function () { return { post: function ($scope, $elm, $attrs, controllers) { var uiGridCtrl = controllers[0], renderContainerCtrl = controllers[1], -->not in rc-16 cellNavController = controllers[2];

-->not in rc-16 // Skip attaching cell-nav specific logic if the directive is not attached above us -->not in rc-16 if (!cellNavController) { return; }

          var containerId = renderContainerCtrl.containerId;

          var grid = uiGridCtrl.grid;

          // Needs to run last after all renderContainers are built
          uiGridCellNavService.decorateRenderContainers(grid);

          // Let the render container be focus-able
          $elm.attr("tabindex", -1);

          // Bind to keydown events in the render container
          $elm.on('keydown', function (evt) {
            evt.uiGridTargetRenderContainerId = containerId;
            return uiGridCtrl.cellNav.handleKeyDown(evt);
          });

So during multiple select, it never reach 'keydown', it just return by the 3rd new line "not in rc-16".

Looking forward to a newer build then.

yleigh avatar Dec 13 '14 04:12 yleigh

Closing as the change has been released with RC's 17 and 18.

c0bra avatar Dec 29 '14 15:12 c0bra