ui-grid,滚动时出错

时间:2015-01-06 21:25:45

标签: javascript angularjs angular-ui-grid

当我滚动ui-grid时,我收到以下错误:

Uncaught TypeError: Cannot read property 'percentage' of undefined

有趣的是,我在ui-grid教程网站上遇到了同样的错误,所以它可能只是一个错误。

这是一个显示issue

的plunker

以下是我正在使用的网格选项:

mc.gridOptions = {
    data: mc.people,
    enableSorting: true,
    onRegisterApi: function( gridApi ) {
      mc.gridApi = gridApi;
    },
    columnDefs: [
      {field: 'name'},
      {field: 'age'},
      {field: 'state', enableSorting: false}
    ]
  };

我在这里做错了什么想法?据我所知,这没有什么不妥。

1 个答案:

答案 0 :(得分:4)

我会在评论框中提到这一点,但我需要空格和格式来解释你可能需要引起他们注意:

首先,您使用的是不稳定版本,最好的办法是使用正在使用和测试的稳定版本。

不稳定版本在下面的代码中引发了一个错误..请查看我在星号(******)中的所有评论:

// Scroll the render container viewport when the mousewheel is used
$elm.bind('wheel mousewheel DomMouseScroll MozMousePixelScroll', function(evt) {
  // use wheelDeltaY

  var newEvent = GridUtil.normalizeWheelEvent(evt);

  var args = { target: $elm };

  *****THIS STATEMENT IS TRUE BECAUSE YOU SCROLLED VERTICALLY, ARGS.Y IS SET*****
  if (newEvent.deltaY !== 0) {
    var scrollYAmount = newEvent.deltaY * -120;

    // Get the scroll percentage
    var scrollYPercentage = (containerCtrl.viewport[0].scrollTop + scrollYAmount) / rowContainer.getVerticalScrollLength();

    // Keep scrollPercentage within the range 0-1.
    if (scrollYPercentage < 0) { scrollYPercentage = 0; }
    else if (scrollYPercentage > 1) { scrollYPercentage = 1; }

    ***THIS IS SET***
    args.y = { percentage: scrollYPercentage, pixels: scrollYAmount };
  }

  *****THIS STATEMENT IS FALSE BECAUSE YOU NEVER SCROLLED HORIZONTALLY, ARGS.X IS NOT SET*****
  if (newEvent.deltaX !== 0) {
    var scrollXAmount = newEvent.deltaX * -120;

    // Get the scroll percentage
    var scrollLeft = GridUtil.normalizeScrollLeft(containerCtrl.viewport);
    var scrollXPercentage = (scrollLeft + scrollXAmount) / (colContainer.getCanvasWidth() - colContainer.getViewportWidth());

    // Keep scrollPercentage within the range 0-1.
    if (scrollXPercentage < 0) { scrollXPercentage = 0; }
    else if (scrollXPercentage > 1) { scrollXPercentage = 1; }

    ***THIS DOESNT GET SET SINCE IT WILL NOT REACH THIS POINT***
    args.x = { percentage: scrollXPercentage, pixels: scrollXAmount };
  }

  *****THROWS AN ERROR BECAUSE ARGS.X IS NULL & DOESNT EXIST*****
  // Let the parent container scroll if the grid is already at the top/bottom
  if ((args.y.percentage !== 0 && args.y.percentage !== 1) || (args.x.percentage !== 0 && args.x.percentage !== 1)) {
    evt.preventDefault();
  }

  uiGridCtrl.fireScrollingEvent(args);
});