Any way to get table nodes or table instance within mData / mRender?
Any way to get table nodes or table instance within mData / mRender?
abilek
Posts: 2Questions: 0Answers: 0
Hi there
I am trying to update/convert my old fnRender functions to mData or mRender and I'm running into a problem. I have attached data to the table itself that I need to use in one of my rendering functions. My current function accesses the table node thusly
[code]
"fnRender": function( oCell ) {
var actionData = oCell.aData[ oCell.iDataColumn ],
oActions = $(oCell.oSettings.nTable).data("actions");
etc...
}
[/code]
There seems to be no way to access the current table node or current instance using mData or mRender. Because I am trying to make this a generic function that I can use on any datatable, and because I might have multiple datatables on a single page, I cannot do what many of your examples suggest, which is to assign the datatables instance to a global variable and use that to access the table node (and thus the data I need).
Similarly, because there may be more than one datatable on a page, I cannot use $.fn.dataTable.fnTables to access the current table node.
Do you have any suggestions as to how I can overcome this problem? It seems a real oversight to me that there is no way to access information about the current settings or instance within mData or mRender.
Thanks very much for any insight you can provide.
Kind regards
anne
I am trying to update/convert my old fnRender functions to mData or mRender and I'm running into a problem. I have attached data to the table itself that I need to use in one of my rendering functions. My current function accesses the table node thusly
[code]
"fnRender": function( oCell ) {
var actionData = oCell.aData[ oCell.iDataColumn ],
oActions = $(oCell.oSettings.nTable).data("actions");
etc...
}
[/code]
There seems to be no way to access the current table node or current instance using mData or mRender. Because I am trying to make this a generic function that I can use on any datatable, and because I might have multiple datatables on a single page, I cannot do what many of your examples suggest, which is to assign the datatables instance to a global variable and use that to access the table node (and thus the data I need).
Similarly, because there may be more than one datatable on a page, I cannot use $.fn.dataTable.fnTables to access the current table node.
Do you have any suggestions as to how I can overcome this problem? It seems a real oversight to me that there is no way to access information about the current settings or instance within mData or mRender.
Thanks very much for any insight you can provide.
Kind regards
anne
This discussion has been closed.
Replies
Allan
http://briancray.com/posts/javascript-module-pattern
That lets us keep an instance of the table within the scope of the module, so we can refer to it anywhere inside that we want.
Another alternative that we use variations of is to have a global function that return a function, i.e. your shared function could be:
[code]
var dependsOnTable = function(myTable)
{
return function(data, type, value)
{
var oActions = myTable.data("actions");
// Do something to return a value
};
};
[/code]
Which would let you do something like the following:
[code]
var myTable1 = $("#firstTable");
myTable1.dataTable(
{
aoColumnDefs : [
mData : dependsOnTable(myTable1)
]
}
);
var myTable2 = $("#secondTable");
myTable2.dataTable(
{
aoColumnDefs : [
mData : dependsOnTable(myTable2)
]
}
);
[/code]