Do I have to call dataTable() on an enhanced table in order to run fnGetSelected()?
Do I have to call dataTable() on an enhanced table in order to run fnGetSelected()?
I'm trying to set up a generic call for fnGetSelected() to select highlighted rows, so I can run it on multiple dataTables instances
The triggering function is fired in my main.js controller with the dataTables config (and fnGetSelected) in a seperate app.js file. I have a global object for "external functions", which I'm adding fnGetSelected to make it callable "from outside"
I have finally got it to work by doing this:
[code]var selected = $.pluginFunctionCaller.getKeys( $('.tbl_orders') );[/code]
and in my dataTables.js utils
[code]fnGetSelected = function( table ) {
var aTrs = table.dataTable().fnGetNodes(),
...
[/code]
I saw in the example that fnGetSelected/fnGetNodes require calling dataTable() on the table, but I did not know I would also have to do this on the already enhanced table.
If I console the table only and the table.dataTable(), they both seem to be identical. However trying to call fnGetNodes() without a prior call to dataTable() just returns ".... is not a function".
Although I don't know of the "payload" of running dataTable() on an already enhanced table, I was wondering if there is a way to run the functions without the additional call?
Let me know if you need the full table initialization.
Thanks your support!
The triggering function is fired in my main.js controller with the dataTables config (and fnGetSelected) in a seperate app.js file. I have a global object for "external functions", which I'm adding fnGetSelected to make it callable "from outside"
I have finally got it to work by doing this:
[code]var selected = $.pluginFunctionCaller.getKeys( $('.tbl_orders') );[/code]
and in my dataTables.js utils
[code]fnGetSelected = function( table ) {
var aTrs = table.dataTable().fnGetNodes(),
...
[/code]
I saw in the example that fnGetSelected/fnGetNodes require calling dataTable() on the table, but I did not know I would also have to do this on the already enhanced table.
If I console the table only and the table.dataTable(), they both seem to be identical. However trying to call fnGetNodes() without a prior call to dataTable() just returns ".... is not a function".
Although I don't know of the "payload" of running dataTable() on an already enhanced table, I was wondering if there is a way to run the functions without the additional call?
Let me know if you need the full table initialization.
Thanks your support!
This discussion has been closed.
Replies
[code]
// add to global functions
$.pluginFunctionCaller.getKeys = fnGetSelected;
[/code]
Allan
[code]
fnGetSelected = function( table ) {
var aTrs = table.dataTable().fnGetNodes(),
bestellkeys = "", ilns = "", newKey, newiln;
for ( var i = 0; i<=aTrs.length-1 ; i++ ) {
thisRow = $(aTrs[i]);
if ( thisRow.find(".selector").is(':checked') == true ) {
newKey = thisRow.find('.loadDetails').jqmData('key');
newIln = thisRow.find('.loadDetails').jqmData('iln');
bestellkeys = bestellkeys == "" ? newKey : bestellkeys+","+newKey;
ilns = ilns == "" ? newIln : ilns+","+newIln;
}
}
return [bestellkeys,ilns]
}
[/code]
Actually the culprit is fnGetNodes(), which I can't get to fire without supplying the already-enhanced table.
[code]
var aTrs = $(table).dataTable().fnGetNodes()
[/code]
if it is already a jQuery object, the jQuery will carry on anyway. If its a selector ('#myTable' for example) then jQuery will do its normal selector thing on it. And if you give it a node, that will also be picked up by jQuery.
Allan
That's why I consoled both:
$('.tbl_orders')
$('.tbl_orders').dataTable()
Which on Firebug are the same, but omitting the call to dataTable() causes the function to fail. That was my question - why the additional call to dataTabel() is required?
Allan
Thanks for clarification.