fnGetAdjacentTr for 1.10
fnGetAdjacentTr for 1.10
I need to iterate my table rows based on current sort and filter criteria, and see that fnGetAdjacentTr is the plug-in to accomplish this.
I included the plugin like this:
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/plug-ins/1.10.10/api/fnGetAdjacentTr.js"></script>
My table is initialized and used like this:
oTable = $('#lynx_table_1').DataTable(defaultOptions);
From the example shown here:
https://www.datatables.net/plug-ins/api/fnGetAdjacentTr
I wrote my test code as follows:
var n1 = $('#lynx_table_1 tbody tr').eq(2)[0];
var next = oTable.fnGetAdjacentTr( n1 );
var prev = oTable.fnGetAdjacentTr( n1, false );
I verified that n1 is pointing at the proper row, but the next line throws the following error:
TypeError: oTable.fnGetAdjacentTr is not a function
Now, I realize that this plug-in is written in the pre-1.10 style, and I am using 1.10, but I thought that including the code, regardless of the style, would work across versions like this.
With 1.10, how do I call this 1.9x plug-in, or is my problem somewhere else?
This question has an accepted answers - jump to answer
Answers
I have a follow-on JQuery question.
Once I get the adjacent row, will it be a tr object like the n1 object? And if so, how do I query this row for an element of a known class? I have an input type in the row that I need to get. Sorry for this elementary question, I am still learning JQuery.
With the 1.10 API I would suggest using
table.rows( { search: 'applied', order: 'applied' } ).nodes().toArray();
to get an array of the nodes. Then you can simply useindexOf
to find your target element and add one to its index.$.hasClass.
Allan