Hi Allan,
I´m using v.1.6.2 of DT Editor ( JS+PHP).
About the last example of the page https://editor.datatables.net/reference/field/select .
In the example it says that it is for standalone mode, but I am using that code with the normal mode of Editor (not standalone mode) and the code itself correctly returns the pair (label, value) but when editing one of the rows, the value of the field select is not the one it had, is the first one that returns the getJSON.
Then when you press the Update button it saves that value (the first one that came from the JSON), not the one it had previously.
Is there a way to use this example in normal Editor mode (not standalone) and that it works?
I need to load the pair (name, letter_id) that comes from the JSON (below) into the pair (label, value) of the select field (this works) and after when you EDIT a row, that field is not automatically overwritten for the first that came on JSON (this is the trouble )
Any idea?
Thank you in advance,
Eduardo
My code - very similar to the example - :
````
var optionsA = [];
function returnNameCarta() {
$.getJSON(parser_origin + parser_root_php + "/php/getDropDownList.php", {
site: id_establecimiento()
},
function(data) {
var option = {};
$.each(data, function(i, e) {
option.label = e.name;
option.value = e.id_carta;
optionsA.push(option);
option = {};
});
}
).done(function() {
editor.field( 'name_carta' ).update( optionsA ); // important
});
};
fields: [
{
label: "Carta Seleccionada:",
name: "name_carta",
type: "select",
options: returnNameCarta(),
},
....
JSON OUTPUT:
0: {DT_RowId: "row_122", name: "Carta Principal", id_carta: "1"}
1: {DT_RowId: "row_123", name: "Carta de Postres", id_carta: "2"}
2: {DT_RowId: "row_124", name: "Carta de Vinos", id_carta: "3"}
3: {DT_RowId: "row_127", name: "Carta de Cócteles", id_carta: "6"}