Often I will want to add all or most columns from a Table's data into the props.columns
array and configure them, however every time I have to add them manually. It would be nice if there was a context option (similar to embedded view params) to add all columns from the data.
In the meantime, you could add a function to your library that you would use in a script transform to populate the columns. When it's populated, remove the binding and you're done.
It's a bit more steps than a built-in functionality, but while waiting for it to be implemented... it can save you some time.
Yeah, that's what I ended up doing and I saved it for future use. I was going to post it but got carried away working
Here it is, in case it's useful to anyone:
Just copy the json, paste it to the binding of the props.columns
, then remove it. It'll create items in props.columns
for each field in the props.data
{
"type": "property",
"enabled": false,
"config": {
"path": "this.props.data"
},
"transforms": [
{
"code": "\td \u003d {\n\t \"field\": \"\",\n\t \"visible\": True,\n\t \"editable\": False,\n\t \"render\": \"auto\",\n\t \"justify\": \"auto\",\n\t \"align\": \"center\",\n\t \"resizable\": True,\n\t \"sortable\": True,\n\t \"sort\": \"none\",\n\t \"filter\": {\n\t \"enabled\": False,\n\t \"visible\": \"on-hover\",\n\t \"string\": {\n\t \"condition\": \"\",\n\t \"value\": \"\"\n\t },\n\t \"number\": {\n\t \"condition\": \"\",\n\t \"value\": \"\"\n\t },\n\t \"boolean\": {\n\t \"condition\": \"\"\n\t },\n\t \"date\": {\n\t \"condition\": \"\",\n\t \"value\": \"\"\n\t }\n\t },\n\t \"viewPath\": \"\",\n\t \"viewParams\": {},\n\t \"boolean\": \"checkbox\",\n\t \"number\": \"value\",\n\t \"progressBar\": {\n\t \"max\": 100,\n\t \"min\": 0,\n\t \"bar\": {\n\t \"color\": \"\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t },\n\t \"track\": {\n\t \"color\": \"\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t },\n\t \"value\": {\n\t \"enabled\": True,\n\t \"format\": \"0,0.##\",\n\t \"justify\": \"center\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t }\n\t },\n\t \"toggleSwitch\": {\n\t \"color\": {\n\t \"selected\": \"\",\n\t \"unselected\": \"\"\n\t }\n\t },\n\t \"nullFormat\": {\n\t \"includeNullStrings\": False,\n\t \"strict\": False,\n\t \"nullFormatValue\": \"\"\n\t },\n\t \"numberFormat\": \"0,0.##\",\n\t \"dateFormat\": \"YYYY-MM-DD HH:mm:ss\",\n\t \"width\": \"\",\n\t \"strictWidth\": False,\n\t \"style\": {\n\t \"classes\": \"\"\n\t },\n\t \"header\": {\n\t \"title\": \"\",\n\t \"justify\": \"left\",\n\t \"align\": \"center\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t },\n\t \"footer\": {\n\t \"title\": \"\",\n\t \"justify\": \"left\",\n\t \"align\": \"center\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t }\n\t}\n\tc \u003d []\n\timport copy\n\tfor col in value.columnNames:\n\t\tdd \u003d copy.deepcopy(d)\n\t\tdd[\u0027field\u0027] \u003d col\n\t\tc.append(dd)\n\treturn c",
"type": "script"
}
]
}
This works only on datasets.
Here's a quick modification to also handle arrays of objects (like the default values when you pull out a table):
json:
{
"type": "property",
"config": {
"path": "this.props.data"
},
"transforms": [
{
"code": "\timport copy\n\tfrom com.inductiveautomation.ignition.common import BasicDataset\n\td \u003d {\n\t \"field\": \"\",\n\t \"visible\": True,\n\t \"editable\": False,\n\t \"render\": \"auto\",\n\t \"justify\": \"auto\",\n\t \"align\": \"center\",\n\t \"resizable\": True,\n\t \"sortable\": True,\n\t \"sort\": \"none\",\n\t \"filter\": {\n\t \"enabled\": False,\n\t \"visible\": \"on-hover\",\n\t \"string\": {\n\t \"condition\": \"\",\n\t \"value\": \"\"\n\t },\n\t \"number\": {\n\t \"condition\": \"\",\n\t \"value\": \"\"\n\t },\n\t \"boolean\": {\n\t \"condition\": \"\"\n\t },\n\t \"date\": {\n\t \"condition\": \"\",\n\t \"value\": \"\"\n\t }\n\t },\n\t \"viewPath\": \"\",\n\t \"viewParams\": {},\n\t \"boolean\": \"checkbox\",\n\t \"number\": \"value\",\n\t \"progressBar\": {\n\t \"max\": 100,\n\t \"min\": 0,\n\t \"bar\": {\n\t \"color\": \"\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t },\n\t \"track\": {\n\t \"color\": \"\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t },\n\t \"value\": {\n\t \"enabled\": True,\n\t \"format\": \"0,0.##\",\n\t \"justify\": \"center\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t }\n\t },\n\t \"toggleSwitch\": {\n\t \"color\": {\n\t \"selected\": \"\",\n\t \"unselected\": \"\"\n\t }\n\t },\n\t \"nullFormat\": {\n\t \"includeNullStrings\": False,\n\t \"strict\": False,\n\t \"nullFormatValue\": \"\"\n\t },\n\t \"numberFormat\": \"0,0.##\",\n\t \"dateFormat\": \"YYYY-MM-DD HH:mm:ss\",\n\t \"width\": \"\",\n\t \"strictWidth\": False,\n\t \"style\": {\n\t \"classes\": \"\"\n\t },\n\t \"header\": {\n\t \"title\": \"\",\n\t \"justify\": \"left\",\n\t \"align\": \"center\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t },\n\t \"footer\": {\n\t \"title\": \"\",\n\t \"justify\": \"left\",\n\t \"align\": \"center\",\n\t \"style\": {\n\t \"classes\": \"\"\n\t }\n\t }\n\t}\n\theaders \u003d value.columnNames if isinstance(value, BasicDataset) else value[0].keys()\n\tc \u003d []\n\tfor col in headers:\n\t\tdd \u003d copy.deepcopy(d)\n\t\tdd[\u0027field\u0027] \u003d col\n\t\tc.append(dd)\n\treturn c",
"type": "script"
}
]
}
Here's the transform code:
import copy
from com.inductiveautomation.ignition.common import BasicDataset
d = {
"field": "",
"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": ""
}
}
}
headers = value.columnNames if isinstance(value, BasicDataset) else value[0].keys()
c = []
for col in headers:
dd = copy.deepcopy(d)
dd['field'] = col
c.append(dd)
return c
There might be other types to handle ? I don't know.