Change style of cell (component Table) via script - Perspective

Hi @truonghaibk94 this may be best done in a script transform of the database binding.

You can loop through the dataset and form an array of dictionaries for each element like this:

data
[
  {
    "colTitle1": {
      "value": "SomeValue",
      "style": {
        "backgroundColor": "#F7901D",
        "classes": "SomeClass"
      }
    },
    "colTitle2": {
      "value": "SomeValue2",
      "style": {
        "backgroundColor": "#FFFFFF",
        "classes": "SomeClass"
      }
    }
  }
  {
    "colTitle1": {
      "value": "SomeValueOnNewRow",
      "style": {
        "backgroundColor": "#00000",
        "classes": "SomeClass"
      }
    },
    "colTitle2": {
      "value": "SomeValueOnNewRow2",
      "style": {
        "backgroundColor": "#FFFFFF",
        "classes": "SomeClass"
      }
    }
  }
]

Basically instead of just having key/value pairs for the columns, turn them into a dictionary in which you can specify value and style properties.

If you place down a a table from the component palette with the default data in you can see this in action for the first cell. It also shows you can do much more than styles.

If you would like any information on how to script this, then let me know.

1 Like