Column rendering based on "options" array returned
Column rendering based on "options" array returned
klingler
Posts: 90Questions: 42Answers: 2
Good morning
I use a returned "options" array for a select field in the editor...all fine:
"options": {
"level": [
{
"label": "n/a",
"value": "0"
},
{
"label": "+12/-12V",
"value": "1"
}
]
}
How could I access the options elements in the datatables render function?
The JSON returned has just the reference to the "level", so 0, 1 and so on...but want to map that to the label value from the options array.
thanks in advance
richard
Answers
Hi Richard,
What you need to do is store the options.level array in a variable scoped so that the rendering function can see it via the
xhr
event:You might want to convert the label / value array into a Map, keyed by the value, so you can do a quick lookup on it.
Allan
Hmm..odd....when I place a console.log inside the xhr Event it is not triggered at all:
Thought there would be already a built-in options to access the options as with the file array used for rendering images.
Is that something worth to implement in the future?
Most columns use a foreign key who's label/values are accessible via the editor's select fields.
Ah found it...should be:
Just for reference for others maybe (o;
Looks like this now:
and the render part:
Oops - you are right. I'm so used to using DataTables'
on()
method which added that namespace automatically!Allan