从 ng-grid 升级到 ui-grid 3.0 时计算列

Calculating columns when upgrading to ui-grid 3.0 from ng-grid

我有一个 plunker 来证明我的问题。

1 问题:总计列为空白

我需要计算列(总计)所以我有一个 $scope 方法如下:

$scope.getTotal = function(a, b, c, d, e) {
    return $filter('number')(Number(a) + Number(b) + Number(c) + Number(d) + Number(e), 2);
  };

和进行该调用的 cellTemplate:

<div class="padd black">
 {{getExternalScopes().getTotal(row.entity.M,row.entity.T,row.entity.W,row.entity.H,row.entity.F)}}
</div>

在 columnDefs 中,我使用:

{
      field: 'total',
      displayName: 'Total',
      enableColumnMenu: false,
      type: 'number',
      cellFilter: 'number:1',
      cellClass: 'text-right',
      headerCellClass: 'text-center',
      cellTemplate: 'total.tmpl.html',
      width: '10%'
    }

[2] 问题:ng-class 在模板中不起作用,pending.icons.html

我们使用图标来指示记录的状态,在模板中,我使用了 ng-class 的条件,它应该控制图标的颜色,但它被忽略了,所有图标都是彩色的黑色:

ng-class="{'cBlue': grid.getCellValue('vote_pending'), 'cGray': !grid.getCellValue('need_vote')}"

呃,这个回答可能只是片面的。

从 v3 开始,外部作用域(可能)已经消失并被 grid.appScope.function_xxx() 取代。阅读更多 here

因此您必须在标记中省略外部范围部分:

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

你的作用域内的计算函数应该是:

  $scope.getTotal=function(a, b, c, d, e) {
    return a+b+c+d+e;
  };

(我没有过滤和数字)

你的单元格模板现在是:

<div class="padd black">
 {{grid.appScope.getTotal(row.entity.M,row.entity.T,row.entity.W,row.entity.H,row.entity.F)}}
</div>

这似乎在这里工作:Plunker

由于我现在正在回家的路上,我稍后会检查您的第 2 期。

希望到目前为止对您有所帮助。

更新:

第 2 期:

pending.icons.html 中使用:

 ng-class="{'cBlue': row.entity.vote_pending, 'cGray': !row.entity.vote_pending}"

对我有用(尽管我的 Plunker 目前非常非常慢)

here