How to get current table instance from a TableTools' button?
How to get current table instance from a TableTools' button?
iceberg
Posts: 14Questions: 0Answers: 0
How to get current datatable instance from a TableTools' button?
Currently I have to pass the raw table id into the button, and then use jquery to dig it out.
sTableId: "blah",
fnClick: function(){
currentDataTableInstance = $(oConfig.sTableId).dataTable();
....
}
I think the cleaner way should be no sTableId needed, just:
currentDataTableInstance = this.fnGetDataTableInstance();
Ray
Currently I have to pass the raw table id into the button, and then use jquery to dig it out.
sTableId: "blah",
fnClick: function(){
currentDataTableInstance = $(oConfig.sTableId).dataTable();
....
}
I think the cleaner way should be no sTableId needed, just:
currentDataTableInstance = this.fnGetDataTableInstance();
Ray
This discussion has been closed.
Replies
this.s.dt.oInstance
[/code]
will give you the DataTables object that the TableTools instance belongs to. This isn't documented yet! Something that will get done when I transition TableTools to the new style of documented like FixedColumns :-)
Allan
By the way, another similar question, how to get current DataTables object from inside a fnRowCallback()?
Thanks in advance.
Ray
Allan
One funny point, though. It seems "this" does not always exactly the same as datatable instance. At least not for fnInitComplete().
var oTable = $("#foo").dataTable({
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
console.log(this==oTable); //that will show many "false" in the console, but then many "true". Strange.
this.fnWhatever(); // it works anyway
return nRow;
},
"fnInitComplete": function () {
alert(this==oTable); //that shows a "false",
this.fnGetNodes(); // How ever, I can still do this. Strange, strange.
}
})
I guess those "false" above is only because the variable oTable is not yet fully initialized. After all, as long as "this" works anyway, I am fine. :-)
Ray