Any easy way to show field label rather than value in datatables?
Any easy way to show field label rather than value in datatables?
Hi Team,
I have configured the editor with a simple select field:
...
label: "Answer:",
name: "Answer",
type: "select",
placeholder: "Select an answer",
...
It works fine, taking data from an ajax call where I fed options data like:
{
"data": [{...}],
"options":{
"Answer": [
{"label":"Yes","value":"1"},
{"label":"No","value":"2"},
{"label":"Ignore","value":"3"},...
]
}
}
I have also configured the Datatable with the column:
...
columns:[
{
data: "Answer",
},...
]
but it show Answer field value. Is there any easy way to show the label put in the options rather then the value?
Thanks,
This question has an accepted answers - jump to answer
Answers
Do you have the label in the data that is being used to load the table as well? If so, reference that. This is how the Editor examples work.
If you don't have it in the data and you can't add it, you'd need to use
columns.render
to render the label in from a value lookup.Allan
Hi Allan
Well, I put the labels in the options array (called "Answer").
I was wondering if I could use this options and avoid to adding labels to any data row.
If is not possible, maybe could be a new feature.
Regards,
Yes it is possible to do - you can assign the
Answer
array to a variable with the rendering function can access inside thexhr
event.However, I would recommend against it. Since its an array for every render it would need to loop over the data. To some extent that could be mitigated by converting the Answer array to a value lookup map in the
xhr
handler, but generally I think its easier to just include the data in the row's data object.Allan
Finally I have followed your suggestion to include the label in row's data obj.
Thanks for your feedback.
Pete