How to show multiple selected options?
How to show multiple selected options?
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
This seems like a fairly simple question but I cannot find the answer anywhere on DT.net. I have an editor form with a select field type. This field type allows users to select multiple options in the dropdown and submit them to the server. All of that works great. However, when I attempt to edit the record again, none of the options are selected. I suspect it is due to the way I am providing that data to editor.
My data looks like:
[
{ "DT_RowId":"1",
"name":"somename",
"options":"1,2"
}
]
In this case lets assume I have a multiple select field simply called options. How do I give editor the information about which option to select? I have also tried:
[
{ "DT_RowId":"1",
"name":"somename",
"options":["1,2"]
}
]
But that doesn't work. Again, this is a very basic question but I can't figure it out. Help!
Thanks!
This question has an accepted answers - jump to answer
Answers
Here is I believe the reference documentation for what you're looking for. I haven't used Editor at all, but I believe your options needs to be an object with a label and value.
Without a test case I cannot try it out, but I'd recommend:
[
{ "DT_RowId":"1",
"name":"somename",
"options":{
"1":1,
"2":2
}
}
]
Can you show me how you define your field type for that? I would expect it to be something like:
Allan
As Allan points out, your second example has an array but only one element:
"1,2"
you may also want to try an array with separate items,"1","2"
Allen and JLegault. Thanks for the info.
This is how my field is set up:
I think JLegault hit the nail on the head, and I need to put quotes around the values instead of having it as a string. I will get it a try and report back.
and just to update, the json that is being passed to Editor looks like:
Which does not work.
One more update, in my comment above where the values are 4,5,6, that was a mistake on my part. The values (currently) are just 1,2,3.
That isn't an array of values though - it is a string.
If it were:
then I would expect it to work.
How are you reading and formatting that information from the database at the moment?
Allan
Allan,
Right now I am populating the datatable via ajax and json. All the data editor needs to update is passed to DT and made available in editor when the record is edited.
I have tried to pass json back that looks like:
But that fails as it is not valid json. I dont know how to pass the proofType without putting quotes around what should be the array.
I am happy to provide login information if you would like to see it in action.
I really appreciate your help!
It is only invalid JSON because of the single quotes - JSON uses double quotes for strings (unless Javascript which can use either - or backticks now).
So this is valid JSON:
Allan
Thanks Allan. I should have been able to figure that out myself.
All is well with the world.