I am using jQuery Datatable and I want to add a button for expand/collapse all row of my table. But I have an issue for the expand when I have row already expanded, and I click on the Button expandALL the row that I expand first is collapsed now and the other expand .. Or if I do the inverse he will be expanded and the other collapse .. How can I do for expand all row even I have already one expand (same case with the collapse)
function init() {
Docu.table = $('.js-table-doc').DataTable(dataTableSettngs());
$('#btn-show-all-doc').on('click', expandCollapseAll);
}
function dataTableSettings() {
return {
responsive: {
details: {
type: 'column'
}
},
serverSide: true,
searching: false,
columnDefs: [
{targets: [0, 8], orderable: false}}
],
columns: [{data: 'id'},
{data: 'name'}]
}
function expandCollapseAll() {
Document.table.rows(':not(.parent)').nodes().to$().find('td:first-child').trigger('click').length ||
Document.table.rows('.parent').nodes().to$().find('td:first-child').trigger('click')
}
