expand/contract all details rows on all pages

expand/contract all details rows on all pages

fly2279fly2279 Posts: 3Questions: 0Answers: 0
edited August 2011 in General
I am using the detail row example here: http://datatables.net/release-datatables/examples/api/row_details.html

I have a link on the page that expands/contracts the details row for every table row all at once with:
[code]
$('.datatable tbody td img').live('click', function (event, expand){
var nTr = this.parentNode.parentNode;

if(this.src.match('icon_minus_circle_frame')){
if(expand != 'expand'){
$(nTr).removeClass('no-bottom-border');
/* This row is already open - close it */
this.src = "img/icons/icon_plus_circle_frame.png";
oTable.fnClose( nTr );
}
} else {
if(expand != 'collapse'){
/* Open this row */
this.src = "img/icons/icon_minus_circle_frame.png";
$(nTr).addClass('no-bottom-border');
var nDetailsRow = oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
nDetailsRow.className += ' '+nTr.className;
$(nDetailsRow).slideDown();
}
}
});

$('.datatable. tbody td img').trigger('click', ['expand']);
[/code]

This is almost the same as the example except I'm using the last jquery selector to 'click' all the images. This works great but when I go to the next page in pagination they are still collapsed after clicking the expand all link. I'm not sure how datatables works but I'm assuming it detaches the rows that are out of view for pagination and so the click trigger doesn't catch those rows out of view. Is there a way to expand all details rows even if they are on the next page?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    if you want specific rows only to be expanded, you'd have to keep some state info (maybe an array of row indexes) and check that when table is redrawn (use one of the callbacks like fnDrawCallback)

    if you want all rows expanded, you just need one value (true or false) but use the same idea with the draw callback.
This discussion has been closed.