Trying to extract a handler (CSS Selector) for the table from the API
Trying to extract a handler (CSS Selector) for the table from the API
I have a function that is used to manage multiple DataTables instances, its given just the API as the only parameter, and each of these tables use different CSS selectors to initiate the DataTables instance, so I can't/shouldn't hardcode the selector in the function.
I was wondering if it was possible to get the CSS selector from the API, I tried all of the following...
var $table = $dt.toJQuery();
var $table = $dt.table();
var $table = $dt.table().toJQuery();
var $table = $dt.table().node();
var $table = $dt.table().node().toJQuery();
// Trying to do something like this..
var whatever = $table.find('tbody>tr:eq(0)>td:eq(0)').text();
The only one that doesnt throw an error is
$dt.table().toJQuery();
But it doesnt return the value im looking for, just empty
Heres the example: http://live.datatables.net/wifeqobi/1/
This question has an accepted answers - jump to answer
Answers
I was able to get the content I wanted by:
example
But is there a way to get the entire table? I tried
Which didnt seem to work
See -
table().node()
.There isn't a way to get the original selector - but hopefully if you've got the node, there shouldn't be any need for it.
One note about the
toJQuery()
method - it will only work on a collection (i.e. an API instance). So it will work onrows().nodes()
for example.row().node()
on the other hand returns a node so there is notoJQuery()
method.Allan
Ah, ok, thanks allan!
Yeah, this is definitely good enough