Answer the question
In order to leave comments, you need to log in
How to get data from Datatables?
Hello, friends. Please help me with the problem, otherwise I'm already confused.
There is some data which I display in DataTables.
The library has good documentation , which describes how to select data.
I actually implemented it with such a script.
$(document).ready(function() {
// Получаем выбранные строки
var table = $('#table_id').DataTable();
$.fn.dataTable.ext.buttons.reload = {
text: 'Загрузить',
action: function alertCountMass() {
var mass = {};
var mass = table.rows( { selected: true } ).data();
var str = JSON.stringify(mass);
alert(str); //
}
};
// Подключаем кнопки
new $.fn.dataTable.Buttons( table, {
buttons: [
{ extend: 'copy', className: 'btn btn-info' },
{ extend: 'excel', className: 'btn btn-info' },
{ extend: 'pdf', className: 'btn btn-info' },
{ extend: 'reload', className: 'btn btn-success' }
]
} );
table.buttons().container()
.appendTo( $('.col-sm-6:eq(0)', table.table().container() ) );
// Подключаем кнопки
$('#table_id').on( 'click', 'tbody tr', function () {
if ( table.row( this, { selected: true } ).any() ) {
table.row( this ).deselect();
}
else {
table.row( this ).select();
}
} );
} );
var mass = {};
var mass = table.rows( { selected: true } ).data();
var str = JSON.stringify(mass);
alert(str);
Answer the question
In order to leave comments, you need to log in
what do you write in the console if you write like this:
var mass = table.rows( { selected: true } ).data();
console log(mass );
console.log(mass(0).data());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question