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

Edit Feature with Cellnav not consistent on last row when hiding horizontal scrollbar

Open estreiten opened this issue 10 years ago • 4 comments

We detected this issue with @andresbiso and @zargoht

Plunker: http://plnkr.co/edit/n2Lf5A4yOBbzCXzkm6fp

It's a basic UI Grid with ui-grid-edit and ui-grid-cellNav features

<div ui-grid="gridOptions" ui-grid-edit ui-grid-cellNav class="grid"></div>

and the horizontal scrollbar hidden.

$scope.gridOptions.enableHorizontalScrollbar = uiGridConstants.scrollbars.NEVER;

Steps to reproduce

  1. Scroll down to the last row of the grid
  2. Single-click the Name cell of the last row ("Marci Emerson" on the example)
  3. Press a character key

It should replace the cell's content with the character inputed as happens with the other rows. Instead of this, it opens the editing field with the previous value loaded and with the input cursor at the end. So pressing new characters will append them at the end of the existing text instead of replacing it.

Note: this behaviour isn't consistent. Sometimes it behaves as expected and sometimes the issue happens. You have to repeat the steps 2 and 3, eventually it will happen.

estreiten avatar Jun 28 '16 15:06 estreiten

Same problem here. Maybe i found the reason in the "s.debounce" function. In version 3.1.0 the timeout will be created like "timeout = $timeout(later, wait);" In the newer versions: "timeout = $timeout(later, wait,false);"

When i delete the third parameter of then angular timeout function (invokeApply) everything works like before.

JZehet avatar Jun 30 '16 07:06 JZehet

Thanks @JZehet for the answer!

Here is how I use it (this way you don't have to change the ui-grid source code);

  • Create a ui-grid-general-decorator.js
'use strict';
angular
  .module('app.core')
  .config(uiGridGeneralConfig);

uiGridGeneralConfig.$inject = ['$provide'];

function uiGridGeneralConfig($provide) {
  $provide.decorator('gridUtil', extendGridUtil);
}

extendGridUtil.$inject = ['$delegate', '$timeout'];

function extendGridUtil($delegate, $timeout) {

   wrap and overwrite gridUtil object methods
   jshint ignorestart 
  var debounce;
  debounce = $delegate.debounce;
   jshint ignoreend 

  $delegate.debounce = function (func, wait, immediate) {
      var timeout, args, context, result;
      function debounce() {
         jshint validthistrue 
        context = this;
        args = arguments;
        var later = function () {
          timeout = null;
          if (!immediate) {
            result = func.apply(context, args);
          }
        };
        var callNow = immediate && !timeout;
        if (timeout) {
          $timeout.cancel(timeout);
        }
        timeout = $timeout(later, wait);
        if (callNow) {
          result = func.apply(context, args);
        }
        return result;
      }
      debounce.cancel = function () {
        $timeout.cancel(timeout);
        timeout = null;
      };
      return debounce;
    };

  return $delegate;
}
  • Remember to include it in your index.html

<script><src=app/core/core-decorators/ui-grid-general-decorator.js><script>

andresbiso avatar Jun 30 '16 13:06 andresbiso

You are right. I don't want to change the source code. But i think it is a ui-grid BUG. Different edit behavior on a cell by changing a scrollbar setting !!!?. Can not be.

Maybe i use your solution. Many thanks.

JZehet avatar Jun 30 '16 14:06 JZehet

Thanks for contributing! This repository has been transferred, and we're preparing the new 5.x release. We're closing older issues and pull requests as part of the reset. Please join us on Discord to follow the work or continue the conversation: https://discord.gg/Baz4w8ZWN

orneryd avatar Aug 12 '26 23:08 orneryd