Datatables traversal

Datatables traversal

girogiro Posts: 6Questions: 0Answers: 0
edited May 2011 in General
I am trying to get the next row in a datatable, below the row that I have currently clicked on. What I am seeing is that the row returned is based on a sorted collection of the first row and not the way the table is displayed on the page.

The table is defined as:

[code]
{
"sScrollY": "400px",
"bScrollCollapse": true,
"bPaginate": false,
"bLengthChange": true,
"bFilter": false,
"bSort": true,
"bInfo": false,
"bAutoWidth": true
}
[/code]

And I am trying to get the next row based on the following code:

[code]
// Get the position of the current data from the node
var posn = table.fnGetPosition( currentRow );

// Get the settings object associated with the table
var oSettings = table.fnSettings();

if (posn < oSettings._iDisplayEnd){
return table.fnGetNodes( posn + 1 );
}
[/code]

Any suggestions on how to do this would be much appreciated.

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Easiest way is to use the plug-in designed for exactly that: http://datatables.net/plug-ins/api#fnGetAdjacentTr :-)

    Allan
  • girogiro Posts: 6Questions: 0Answers: 0
    edited May 2011
    Hey Allan,

    That's great news! Unfortunately, I can't get that to work. I keep getting an exception when calling the fnGetAdjacentTr API:

    [code]
    Uncaught TypeError: Object [object Object] has no method 'fnGetAdjacentTr'
    [/code]

    I am calling that function as:

    [code]
    nextRow = table.fnGetAdjacentTr( currentRow );
    [/code]

    Here is how I am trying to include that API on the page:

    [code]


    [/code]

    I have also tried to include it as:

    [code]


    [/code]

    Neither approach seems to work. How do I go about using this API?

    Thanks!
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    What is the 'table' variable - I'm guessing not the DataTables instance (as your includes look fine - assuming you copied the function into the file dataTables.fnGetAdjacentTr.js?). It should just need $('#mytable').dataTable().fnGetAdjacentTr( current Row );

    Allan
  • girogiro Posts: 6Questions: 0Answers: 0
    Okay, so that was what was missing -- copying the function into a file. Now, does each API function have to go into a separate file or can I put them into a dataTables.commonAPIs.js file and reference them there?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    You can lump them all into one file if you wish. They just need to be loaded after DataTables but before you actually use them :-)

    Allan
This discussion has been closed.