UI网格将计算应用于列

时间:2017-04-10 23:43:46

标签: angularjs angular-ui-grid ui-grid

现在,当我更改%Discount字段值时, “产品列动态总计”更改。 我还希望“x(默认)”列单元格值在%变化方面也会发生变化。

https://plnkr.co/edit/B40h9XrKOcNly7M0HG0u?p=preview

data.data <- data.frame(Categorical=c("First", "Second", "Third", "Fourth"), Mean=c(25, 40, 90, 65))

ggplot(data=data.data, aes(Categorical, Mean)) +
  geom_bar(stat="identity", fill="white", width=0.75, color="black") + 
  scale_y_continuous(breaks=seq(0,100,20), minor_breaks=seq(10,100,20), limits=c(0,100), expand=c(0,0)) +
  theme(axis.title=element_text(size=12, face="italic"), 
        axis.text=element_text(size=12, face="plain"),
        axis.line=element_line(color="black", size=0.5),
        panel.grid.major.y=element_blank(),
        panel.grid.minor.y=element_blank(),
        panel.grid.major.x=element_blank(),
        panel.grid.minor.x=element_blank(),
        panel.background=element_blank())

2 个答案:

答案 0 :(得分:1)

$scope.myData更改时,您可以收听更改并更新discount。由于ui-grid$scope.myData具有双向绑定,因此它将更新视图。 您input标记看起来像是:

<input class="form-control "  data-ng-model="discount" ng-change="updateValues()" type="number">

然后将updateValues功能添加到您的$scope

$scope.updateValues = function() {
   // write code to update values here
}

答案 1 :(得分:0)

将您的plunker分叉以更改“x(默认)”列的值以及一些随机值。

代码:

angular.forEach($scope.myData,function(row,idx){ row.x = Math.random(); });

不建议使用观察者来实现功能。而是使用函数。