我遇到了同樣的問題,並嘗試了一些建議的解決方案,我發現但沒有與我的網格版本一起工作。我搜索了網格源,並找到了我用於聚合行的模板並複製了它,然後調整爲在我的方法中包含調用顯示部分的函數:
在我的gridOptions上,我定義了下面顯示的屬性
aggregateTemplate: "<div ng-click=\"row.toggleExpand()\" ng-style=\"rowStyle(row)\" class=\"ngAggregate\">" +
" <span class=\"ngAggregateText\"><span class='ngAggregateTextLeading'>{{row.totalChildren()}} {{row.label CUSTOM_FILTERS}} {{entryMaybePlural(row)}}</span><span>Total Weight: {{aggFunc(row)}} lbs {{AggItemsLabel}}</span></span>" +
" <div class=\"{{row.aggClass()}}\"></div>" +
"</div>" +
""
在控制器上的網格的範圍我具備的功能
$scope.aggFunc = function (row) {
var total = 0;
angular.forEach(row.children, function(cropEntry) {
total+=cropEntry.entity.weight;
});
return total.toString();
};
$scope.entryMaybePlural = function (row) {
if(row.children.length>1)
{
return "entries";
}
else
return "entry";
};
你會在兩種情況下,看到我通過該行的模板功能的控制器範圍,然後我看着名爲兒童的財產n行(當其他嘗試沒有解決時,我只是使用Chrome調試工具計算出來的)。
PS我的網格有這個編譯評論在頂部,雖然沒有版本:|
/***********************************************
* ng-grid JavaScript Library
* Authors: https://github.com/angular-ui/ng-grid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 06/03/2013 21:19
***********************************************/
我相信這很大程度上取決於您使用的網格版本。我在網上發現了一些解決這個問題的方法,但網格的功能和內部數據模型在我發現的着作和當前版本之間發生了變化,我將在下面發佈我的當前解決方案,但是您可能需要深入瞭解網格代碼在你的版本中找到模板,然後從那裏調整/檢查。 – shaunhusain
我使用NG-電網2.0.5版本 – Kabb5
老實說才意識到我不知道我是哪一個就在此時,正好有時間戳熄滅的......我會後我做了什麼無論如何。 – shaunhusain