Get checked row after checked dynamically from Ajax
Get checked row after checked dynamically from Ajax
simsar78
Posts: 3Questions: 1Answers: 0
Hello,
i have this table rendered whit Ajax from database:
<table id="list" class="table table-striped table-bordered table-sm no-footer dataTable" style="width: 100%; font-size: 14px;" role="grid" aria-describedby="list">
<thead>
<tr role="row">
<th class="select-checkbox sorting_asc" tabindex="0" aria-controls="list" rowspan="1" colspan="1" aria-label="" style="width: 0px;"></th>
<th class="sorting" tabindex="0" aria-controls="list" rowspan="1" colspan="1" aria-label="Code: activate to sort column ascending" style="width: 0px;">Code</th>
</th></tr>
</thead>
<tbody>
<tr class="odd">
<td class="select-checkbox sorting_1"></td>
<td>18081</td>
// ...
AJAX:
$('#list').DataTable().destroy();
table = $('#list').DataTable( {
"ajax": {
"url": "requests/List.php",
"type": "POST",
"data": {"id":id},
"dataType": "json",
"cache": false,
"dataSrc": ""
},
"columns" : [
{ "data": null, defaultContent: '' },
{ "data": "code" },
],
columnDefs: [ {
orderable: false,
className: 'select-checkbox',
targets: 0,
} ],
createdRow: function (row, data, index) {
$.each(data_dip, function (k, v) {
// check dynamically checkbox in column 0
if(data.codice == v.codice){
$(row).addClass('selected');
}
});
//
},
select: {
style: 'multi',
selector: 'td:first-child'
},
"lengthMenu": [[20, 50, 100, -1], [20, 50, 100, "Tutti"]]
});
if request the selected rows I have no result:
var selectedCodOpe = table.rows( { selected: true } ).data().toArray()
Why ?
- data_dip is my array
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
That should work. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
I try to use live.datatables
http://live.datatables.net/virixaro/2/
Your example has an extra
}causing a syntax error. I fixed that and updated your example to get the selected rows. You are adding the classselectedincreatedRow. This isn't selecting the rows, its just adding the class and styling. Use theselect()API ininitCompleteto select the rows that have the classselected. Like this:http://live.datatables.net/virixaro/3/edit
Kevin
@kthorngren

Thank you very much... it's function ... Yeahhhh