How do you open a new instance of DT in a seperate window/tab, but with a different pageLenght?
How do you open a new instance of DT in a seperate window/tab, but with a different pageLenght?
rldean1
Posts: 141Questions: 66Answers: 1
I have a custom button that launches the same *.html page containing my table in a new tab.
I found this method: table.page.len( 100 ).draw();
{
text: 'New Tab' + '<i class="fas fa-external-link-alt fa-fw"></i>',
titleAttr: 'Launch this table in a seperate tab',
className: 'btn-primary',
init: function (dt, node, config) {
console.log(node)
$(node).removeClass('btn-secondary');
},
action: function (e, dt, node, config) {
var win = window.open('jobspecs.htm', '_blank');
//table.page.len( 100 ).draw();
win.focus();
console.log(win);
}
}//end custom button
How do I make changes to table
in the new tab? OR, is there a better programmatic way to call a new instance of DT in a separate window?
The only way I know how I might be able to accomplish this is by using jQuery to manipulate pageLength:
in win.document.body
This discussion has been closed.
Answers
Hi @raydlevel5 ,
Yep, you can just access the table with standard jQuery selectors, so something like:
$('#idOfTableInNewTab').DataTables().page.len(100).draw();
Hope that helps,
Cheers,
Colin
@colin I'm opening the same page, but in a new tab, so the table has the same #id. When I attempt to manipulate the table in the new tab, I actually end up manipulating the table in the parent window, not the table in the new tab...
Yep, but you'd make the selector specific to the new window. This StackOverflow discussion should help.
Cheers
Colin
OK, so I've proved that I can target the DataTable in the NEW window, however, I'm still having issues.
Now, if I try to call the
page.len()
method, it thinks I'm trying to reinitialize the table, which I'm not. (I tried to bypass this error withretrieve
, but that didn't work either).The following code generates this error: Uncaught TypeError: Cannot read property 'aDataSort' of undefined
So, I also tried to create a function that could be called after initialization, but this is where it thinks I'm trying to reinitialize.
The following code generates this error: _DataTables warning: table id=tblJobSpecs - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3_
So, I can manipulate the DOM in the new window, but I can't call
page.len()
.Hi @raydlevel5 ,
Sorry, I just realised I haven't replied to this one. Is it an issue still or did you resolve the problem?
Cheers,
Colin
@colin I gave up and ended up creating a brand new HTML/JS doc with the desired pageLength. This is not critical and can be closed.
I couldn't figure out how to manipulate the table in a new tab... this doesn't work:
Now I'm wondering if I should have dropped .draw().
Anyway, we're good, thanks for all the help!!
Shame we couldn't get to the bottom of it, but glad you had a workaround
C