Set cell value based on a condition
Asked Answered
S

1

1

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?

Serviette answered 17/3, 2016 at 19:47 Comment(3)
Your question is not clear. first, which is the condition? Based on what you want to set S or L in cells?Simferopol
I found my answer on @nabinca post hereServiette
Glad to hear that :)Simferopol
S
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
    };
Serviette answered 1/4, 2016 at 19:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.