Options array
Options array
![abarnes](https://secure.gravatar.com/avatar/82a61d92185274f3e0c4ac0f59c8e851/?default=https%3A%2F%2Fvanillicon.com%2F82a61d92185274f3e0c4ac0f59c8e851_200.png&rating=g&size=120)
Pulling my hair out. I'm trying to populate a select field with data from ajax response.
This is my ajax response:
{
"data": [{
"DT_RowId": "row_00001",
"deviceAsset": "Click to Add...",
"deviceOwner": "Users Name",
"deviceLocation": "The Location",
"deviceDept": "The Dept"
}],
"options": {
"deviceLocation": [{
"label": "Location 1",
"value": "Location 1"
}, {
"label": "Location 2",
"value": "Location 2"
}, {
"label": "Location 3",
"value": "Location 3"
}]
},
"files": []
}
This is my editor declare:
editor = new $.fn.dataTable.Editor( {
ajax: deviceTBL+'&request=system',
fields: [ {
label: "Asset:",
name: "deviceAsset"
},
{
label: "Owner:",
name: "deviceOwner"
},
{
label: "Location:",
name: "deviceLocation",
type: "select",
placeholder: "Select a location"
},
{
label: "Department:",
name: "deviceDept"
},
]
} );
The data loads in the table no issues. But when I click to edit in bubble, the dropdown is empty except for the place holder. What am I missing?
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Hi,
I don't immediately see anything wrong there. Could you show me your DataTables initialisation and also take a trace with the debugger please - click the Upload button and then let me know what the debug code is.
Thanks,
Allan
With this particular one I am using my own ajax script. I initialize with this and call a function. It works perfect except for the options on select. I can edit fields etc.
Another thing I find strange through debugging is if the Location field is set as type "select", everytime I update a field it sends the field location to be updated as well. For example if I update Asset, the data submits to change Asset and Location. If I declare the field as a regular field this doesn't happen.
For clarification what I'm trying to accomplish is user clicks a regular field to edit and editor provides a dropdown of choices. I don't want the dropdown in the regular table.
I'm also using the standalone option as I'm updating labels instead of tables
UPDATE:
Here is what I finally got to work. Is this the proper way to load select options for 2 fields?
Last Update: This is the final code. Is this the best way? Works perfect.
That would do it. If you aren't using DataTables' own
ajax
option then Editor can't auto detect the options. So yes, thefield().update()
method is the correct way of doing this.Allan