Best way to show a selected option in dropdown list on Editor form when editing datatable row?
Best way to show a selected option in dropdown list on Editor form when editing datatable row?
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I have pages where I am using a datatable and also editor framework for adding, editing, deleting records, and some have a populated dropdown list based on api call to show all available options for that field. This is working well. Does anyone know how to have the editor form appear when editing a row showing selected option based on row field value?
Here is an example of how I am populating drop down. So, to reiterate, what I want is to have the 'torque_tool_id' field have the same item id selected as the number of the torque_tool_id stored in the row of table that is being edited.
Any help would be appreciated, thanks very much
optionsA = [];
});
$.getJSON("/assy-torque/api/torquevalues/GetTorqueToolData", {
term: "-1"
},
function (data) {
var option = {};
data.forEach(obj => {
Object.entries(obj).forEach(([key, value]) => {
option.label = value.tool_label;
option.value = value.id;
optionsA.push(option);
option = {};
});
})
}
).done(function () {
editorStationJob.field('torque_tool_id').update(optionsA);
optionsA = [];
});
Answers
I'm really sorry - I'm not quite getting it! Possibly too early on a Monday morning ;-).
It sounds like
torque_tool_id
should be taking the value that is sorted in the db, but that should really be happening as a matter of course. Consider this example theusers.site
field takes the value of the site id when triggering editing.Apologies for not getting it - could you elaborate a little, and ideally link to an example?
Regards,
Allan