angular-ui / ui-grid

UI Grid: an Angular Data Grid
http://ui-grid.info
MIT License
5.39k stars 2.47k forks source link

Editing a cell partially in view fails #5161

Open sdesmond opened 8 years ago

sdesmond commented 8 years ago

This happens when there are enough rows to warrant vertical scrolling. You can kind of see what's happening better on IE11, but it fails in Chrome too.

http://plnkr.co/edit/H7q2BsQupSBI4Um1BmUt?p=preview

Steps to reproduce:

  1. Scroll to bottom row.
  2. Row 3 should be about half visible.
  3. Double-click the "Gender" column on row 3 to begin editing.
  4. Row 3 scrolls into view and the editor starts and stops instantly.
  5. If you haven't manually scrolled, none of the edits for row 3 work until you scroll.

From the debugging I've done, when beginEditAfterScroll() in the uiGridCell directive runs, it sets up the deregOnGridScroll() function. This function is invoked immediately after edit begins so the edit is immediately canceled.

It may be that Grid.prototype.scrollToIfNecessary() is trying to scroll when its not needed.

sdesmond commented 8 years ago

Anyone had a chance to look at this yet?

romojt commented 8 years ago

I'm having a similar problem. When I'm trying to edit a partially visible field the deregOnGridScroll() is invoked immediatly.

In my case it only happens when it is the last row that is partially hidden and the part that is hidden is less than the width of the horizontal scrollbar. In the Grid.prototype.scrollToIfNecessary() method the scrollLength is set to a negative number here:

// Total vertical scroll length of the grid
        var scrollLength = (self.renderContainers.body.getCanvasHeight() - self.renderContainers.body.getViewportHeight());

Which means that the percentage in the ScrollEvent is a negative number:

// Turn the scroll position into a percentage and make it an argument for a scroll event
          percentage = scrollPixels / scrollLength;
          scrollEvent.y = { percentage: percentage  };

And when the scrollPercentage is a negative number the scrollTop get set to 0 because in ScrollEvent.prototype.getNewScrollTop

return Math.max(0, scrollYPercentage * scrollLength);

But setting the scrollTop to 0 still leaves the field only partially visible which for some reason fires a scrollevent that cancels edit mode.