There is a way to get a JSON array to populate the drop-down list the moment you click on the edit link, so you get your JSON through the "full" pretty "successful" attribute of your AJAX call inside "fnServerData" like this:
"fnServerData": function(sSource, aoData, fnCallback, oSettings) { oSettings.jqXHR = $.ajax({ "dataType": 'json', "type": "POST", "url": sSource, "data": "opcionesMenu=ini", "success": fnCallback, "complete": function(resp) { jsonSelects = JSON.parse(resp.responseText); } }); }
In my example, "jsonSelects" is a global variable where I can get my JSON everywhere inside my code, then I will use my JSON to populate the drop-down list when editing as follows:
function editRow(oTable, nRow) { var aData = oTable.fnGetData(nRow); var jqTds = $('>td', nRow); //Dropdown list jqTds[2].innerHTML = '<select id="selMenu"></select>'; for(i = 0; i < jsonSelects.menu.length; i++) { $('#selMenu').append('<option value=' + jsonSelects.menu[i].cod_elemento + '>' + jsonSelects.menu[i].nombre_elemento + '</option>'); } //Dropdown list jqTds[3].innerHTML = '<select id="selIdioma"></select>'; for(i = 0; i < jsonSelects.idioma.length; i++) { $('#selIdioma').append('<option value=' + jsonSelects.idioma[i].codigo_idioma + '>' + jsonSelects.idioma[i].nombre_idioma + '</option>'); } // Input text jqTds[4].innerHTML = '<input value="' + aData["opcion"] + '" type="text">';
When you click the "Edit" link, you will receive a drop-down list in the fields that you would like.
source share