Logic within json

Is it possible to add some logic in one of the fields
This script loops through my dataset and creates all the columns based on my headers in the dataset.
But I would like to be able to change the Title based on my header Value,

image

headers = value.getColumnNames()
true=True
false = False

return [ {
  "field": header,
  "visible": true,
  "editable": false,
  "render": "auto",
  "justify": "auto",
  "align": "center",
  "resizable": true,
  "sortable": true,
  "sort": "none",
  "filter": {
    "enabled": false,
    "visible": "on-hover",
    "string": {
      "condition": "",
      "value": ""
    },
    "number": {
      "condition": "",
      "value": ""
    },
    "boolean": {
      "condition": ""
    },
    "date": {
      "condition": "",
      "value": ""
    }
  },
  "viewPath": "",
  "viewParams": {},
  "boolean": "checkbox",
  "number": "value",
  "progressBar": {
    "max": 100,
    "min": 0,
    "bar": {
      "color": "",
      "style": {
        "classes": ""
      }
    },
    "track": {
      "color": "",
      "style": {
        "classes": ""
      }
    },
    "value": {
      "enabled": true,
      "format": "0,0.##",
      "justify": "center",
      "style": {
        "classes": ""
      }
    }
  },
  "toggleSwitch": {
    "color": {
      "selected": "",
      "unselected": ""
    }
  },
  "nullFormat": {
    "includeNullStrings": false,
    "strict": false,
    "nullFormatValue": ""
  },
  "numberFormat": "0,0.##",
  "dateFormat": "YYYY-MM-DD HH:mm:ss",
  "width": "",
  "strictWidth": false,
  "style": {
    "classes": ""
  },
  "header": {
    "title": "",
    "justify": "left",
    "align": "center",
    "style": {
      "classes": ""
    }
  },
  "footer": {
    "title": "",
    "justify": "left",
    "align": "center",
    "style": {
      "classes": ""
    }
  }
} for header in headers ]

This is not json, this is a python dict. You can do whatever you want that's allowed by python.

return [
    {
        'header': {
            'title': header.title().replace('_', ' ').whateveryouwant()
        }
    } for header in headers
]

Why ?

2 Likes


That's why,
I haven't tested by simply replacing them, here I could simply copy paste the column setup from the table

A tip for next time: You don't need to paste the whole thing, only the properties you want to change.
The other ones will just use the defaults.

Yes you are right but I always come up with a new idea or someone wants the data presented in another way me or can you change that.
So for me it works better with the whole structure from the start