Any easy way to show field label rather than value in datatables?

Any easy way to show field label rather than value in datatables?

p3loadsp3loads Posts: 11Questions: 3Answers: 0

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

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    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

  • p3loadsp3loads Posts: 11Questions: 3Answers: 0

    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,

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Yes it is possible to do - you can assign the Answer array to a variable with the rendering function can access inside the xhr 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

  • p3loadsp3loads Posts: 11Questions: 3Answers: 0

    Finally I have followed your suggestion to include the label in row's data obj.
    Thanks for your feedback.

    Pete

This discussion has been closed.