I have the following table:
$(document).ready(function() {
var table = $('#tblClientes').DataTable({
'select': true,
'paging': true,
'info': true,
'filter': true,
'stateSave': true,
'processing': false,
'serverSide': false,
.....
});
});
And the following code too:
var mult_select = function(tbody, table){
$('#tblClientes tbody').on( 'click', 'tr', function () {
table.on('select.dt', function() {
var array = [];
table.rows('.selected').every(function(rowIdx) {
array.push(table.row(rowIdx).data())
});
console.log(array);
});
});
}
The objective is that when selecting a set of rows you can send the id of each one of them by ajax to make an SQL query.
The problem is that the console.log(array) every time I select or deselect it shows me more and more, it's as if they were accumulating. I want every time I select one or two (or more) to show them all in the same object within the array as the second display of the image.
Thanks in advance !!
It uses a counter and when adding the data to the array, instead of using the push function, indicate yourself the id to use to save it in the array.