How to get the drop down selected value in a data table when a particular row is selected?
How to get the drop down selected value in a data table when a particular row is selected?
premagopu
Posts: 1Questions: 1Answers: 0
Below is my code. I have dynamically inserted a dropdown based on the JSON value from the back end. How to get the selected value of the drop down, when a row is selected?
$('#configFieldTable').DataTable({
columns: JSON.parse(field.dtHeader),
data: JSON.parse(field.dtData),
"scrollCollapse": true,
"paging": false,
"searching": true,
"info": false,
"autoWidth": false,
columnDefs: [
{
"defaultContent": "-",
"targets": "_all",
"visible": false, 'targets': [10]
},
{"width": "5px", "targets": 0},
{"width": "5px", "targets": 1, "visible": false},
{"width": "100px", "targets": 2},
{"width": "80px", "targets": 3,
"render": function ( data, type, full, meta ) {
if(data=="yes") {
return '<select id="aggregate"><option value="1" selected="selected">select</option><option value="2">sum</option><option value="3">max</option></select>';
}else{
return "";
}
}
},
{"width": "5px", "targets": 4, "visible":false},
{"width": "10px", "targets": 5},
{"width": "10px", "targets": 6},
{"width": "10px", "targets": 7},
{"width": "10px", "targets": 8},
{"width": "10px", "targets": 9},
{
orderable: false,
className: 'select-checkbox',
bSortable: false,
targets: 0
}
],
select: {
style: 'multiple',
selector: 'td:first-child'
}
});
This discussion has been closed.
Answers
Hi @premagopu ,
This example here shows how to get the row contents when clicked upon. To get the contents of the dropdown, you would probably just use jQuery to get the
.val()
of that node,Cheers,
Colin