根据条件设置单元格值 [英] Set cell value based on a condition
本文介绍了根据条件设置单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列绑定到一个名为 state
的 field
,它的值是:S
或 L
.我想将其映射到以下内容:
S
=> Short
,L
=> Long
绑定是这样定义的:
$scope.gridOptions = {启用排序:真,启用过滤:真,启用水平滚动条:0,列定义:[{名称:'动作',字段:'状态',宽度:110,启用过滤:假}]};
我已经在使用 cellclass
和 celltemplating
,但其中一个分别用于类应用程序或事件绑定.如何根据 ng-if
设置单元格值?
解决方案
如果它对任何人有帮助,我最终会这样做:
let stateTemplate = "{{row.entity.state == 'L' ? 'Buy' : 'Sell'}}</div>"$scope.gridOptions = {启用排序:真,启用过滤:真,启用水平滚动条:0,列定义:[{name: 'action', field: 'state', cellTemplate: stateTemplate, enableFiltering: false}],数据:一些数据};I have a column binded to a field
called state
, which has the values: S
or L
. I want to map this to following:
S
=> Short
,
L
=> Long
This is how the binding is defined:
$scope.gridOptions = {
enableSorting: true,
enableFiltering: true,
enableHorizontalScrollbar: 0,
columnDefs: [
{name: 'action', field: 'state', width: 110, enableFiltering: false}
]
};
I am already using cellclass
and celltemplating
, but either one is used for class application or event binding respectively. How do I set cell value based on an ng-if
?
解决方案 If it helps anyone, I ended up doing this:
let stateTemplate = "<div>{{row.entity.state == 'L' ? 'Buy' : 'Sell'}}</div>"
$scope.gridOptions = {
enableSorting: true,
enableFiltering: true,
enableHorizontalScrollbar: 0,
columnDefs: [
{name: 'action', field: 'state', cellTemplate: stateTemplate, enableFiltering: false}
],
data: someData
};
这篇关于根据条件设置单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文