Edit new created row before adding to datatables, with jquery
Edit new created row before adding to datatables, with jquery
itajackass
Posts: 162Questions: 48Answers: 3
I've a script that insert a new row inside a table with ajax:
I need to edit a <select> inside the new added row (plain text) and set a selected value. In this example 5. But with my code it doesn't work: $(tr).find(".select").val(idSelect);
What't the correct way?
var idSelect = "5";
$.ajax({
type: "POST",
async: false,
dataType:"text",
url: "ajax/get-new-row.php",
data: { },
success: function(data) {
var tr = tabella.row.add(
$(data)[0]
);
$(tr).find(".select").val(idSelect); // doesn't work
tabella.row(tr).draw( false ).node();
tabella.rows().invalidate('dom').draw(false);
}
});
This discussion has been closed.
Answers
var tr
is not a node. You'd need to use:instead. As the
row.add()
documentation states, it returns a DataTables API instance with the newly added row selected.Allan