Estoy construyendo un DataTable y todo funciona perfectamente bien.
una de las columnas, necesito representar una lista de selección/desplegable y establecer el valor seleccionado predeterminado.
logré renderizar
render: function (data) { //eg data.selectedvalue = 1 or 2 or 3 var select = $("<select class='target' id='empstatus'><option value ='1'>Open</option><option value ='2'>Close</option><option value ='3'>N/A</option></select>"); //tried to set value - but it is not setting default selection, always shows the first selection after it renders select.val(data.selectedvalue).attr('selected', 'selected'); return select.prop("outerHTML"); }Esta lista muestra mi pregunta: ¿cómo puedo establecer un valor dinámico seleccionado?
Debe establecer el atributo de la opción apropiada, no el menú desplegable, para que se incluya en el outerHTML .
render: function (data) { //eg data.selectedvalue = 1 or 2 or 3 var select = $("<select class='target' id='empstatus'><option value ='1'>Open</option><option value ='2'>Close</option><option value ='3'>N/A</option></select>"); select.find(`option[value=${data.selectedvalue}]`).attr('selected', 'selected'); return select.prop("outerHTML"); }