Programmatically select rows
Programmatically select rows
jrenaut
Posts: 3Questions: 0Answers: 0
I'd like to implement a "Select Visible" button that would only select the rows currently visible on screen. Not a big deal - here's the snippet defining my buttons:
[code]"aButtons": [ "select_all", "select_none",
{
"sExtends": "text",
"sButtonText": "Select Visible",
"fnClick": function ( nButton, oConfig, oFlash )
{
var oTable = $('#mytable').dataTable();
var nodes = oTable.fnGetDisplayNodes();
for (var i=0; i
[code]"aButtons": [ "select_all", "select_none",
{
"sExtends": "text",
"sButtonText": "Select Visible",
"fnClick": function ( nButton, oConfig, oFlash )
{
var oTable = $('#mytable').dataTable();
var nodes = oTable.fnGetDisplayNodes();
for (var i=0; i
This discussion has been closed.
Replies
Allan
Allan [/quote]
Hello
I would love to check if it isn't selected already, but it doesn't work.
This is my code:
[code]
var oTT = TableTools.fnGetInstance('my_table');
var rVis = oTable.fnGetDisplayNodes();
for (var i=0; i
[code]
if (oTT.fnIsSelected( rVis[i] )) {
[/code]
work now it will :-)
Allan
spammed the topic with my problem and solution for other people, since it's not a native function, and you have to use both API's to do what I wanted. DataTables and TableTools.
Thanks anyhow!
So I either need a Datatables API method that selects a row, or I need to know how to simulate a click with the 'delegate' method (which, I believe, is the new way to use jQuery "Live").
Any ideas?
In TableTools that API method is fnSelect. DataTables itself does not have row selection abilities built in (TableTools provides that feature as an optional extra).
> I need to know how to simulate a click with the 'delegate' method
$(myElement).click(); should do the job just fine.
Perhaps you can use http://live.datatables.net to show us an example of the problem you are having?
Allan
cliftonite:
I think the best way to select a row is add the "DTTT_selected" class to the node and push the node to "selected" array. (of course you have to use TableTools)
[code]
$(nodes[i]).addClass('DTTT_selected');
TableTools.fnGetInstance('oTable').s.select.selected.push(nodes[i]);
[/code]