Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Check for cellNav in sub-grid is truthy because of cellNav on parent grid #2294

Closed
01willtx opened this issue Dec 8, 2014 · 4 comments
Assignees
Milestone

Comments

@01willtx
Copy link

01willtx commented Dec 8, 2014

It is happening at this line of code (11418): if (uiGridCtrl.grid.api.cellNav.getFocusedCell() == null)

The grid loads fine but any scrolling causes the error, whether the scrolling is within an expandable row or the grid itself. Something else I noticed but doesn't happen every time, the headers disappear when fully scrolling but I think it may be a browser resize issue. I'll try to reproduce it again.

BTW, great job and many thanks!!!

@c0bra
Copy link
Contributor

c0bra commented Dec 8, 2014

This should be fixed with 9bfa6e3. assuming you're including the cellNav module but not adding the directive to your grid. Is that the case?

@wgorder
Copy link
Contributor

wgorder commented Dec 9, 2014

@c0bra Its not my case. I have the cellNav module on my grid. When using the expandable grid option I get this error while the grid is expanded and I attempt to scroll.

Essentially what is happening is in the code below the error is thrown on this line

 $scope.$on(uiGridConstants.events.GRID_SCROLL, function (evt, args) {
                // Skip if there's no currently-focused cell
                if (uiGridCtrl.grid.api.cellNav.getFocusedCell() == null) { //error thrown here cellNav is null
                  return;
                }

I do have your patch..  Here is a the surrounding code.

  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],
                  cellNavController = controllers[2];

              // Skip attaching cell-nav specific logic if the directive is not attached above us
              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);
              });

              // When there's a scroll event we need to make sure to re-focus the right row, because the cell contents may have changed
              $scope.$on(uiGridConstants.events.GRID_SCROLL, function (evt, args) {
                // Skip if there's no currently-focused cell
                if (uiGridCtrl.grid.api.cellNav.getFocusedCell() == null) {
                  return;
                }

@wgorder
Copy link
Contributor

wgorder commented Dec 9, 2014

FYI adding cell nav to the expandable template solved the problem. The issue was cell nav was on the parent grid but not present on the expandable grid.

div(ui-grid='row.entity.subGridOptions' ui-grid-cellNav)

@c0bra
Copy link
Contributor

c0bra commented Dec 9, 2014

OK so I imagine that what's happening is the uiGridRenderContainer and uiGridCell directives are requesting the uiGridCellnav controller with ?^uiGridCellnav. It's correctly not coming from the immediate parent grid (the subgrid) because it doesn't have the ui-grid-cellnav directive applied, but it IS coming from the subgrid's parent grid, although it shouldn't.

I'm not really sure of the right way to fix this, but it seems like we might need to do a recursive backwards search of parent nodes to see if the closest 'ui-grid' element has the ui-grid-cellnav directive, and stop there, rather than using the controller existence check.

NB: I'm changing this issue's title to clarify the problem.

@c0bra c0bra changed the title ui-grid rc 3.0.0-rc16 Cannot read property getFocusedCell of undefined Bug: Check for cellNav in sub-grid is truthy because of cellNav on parent grid Dec 9, 2014
@c0bra c0bra self-assigned this Dec 9, 2014
@c0bra c0bra added this to the 3.0 milestone Dec 9, 2014
@c0bra c0bra closed this as completed in 1426454 Jan 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants