Set cell value based on a condition

为君一笑 提交于 2019-12-24 12:43:39

问题


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?


回答1:


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
    };


来源:https://stackoverflow.com/questions/36070340/set-cell-value-based-on-a-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!