| 4 |
lars |
1 |
/**
|
|
|
2 |
* Due to the fact that DataTables moves DOM elements around (mainly `dt-tag tr`
|
|
|
3 |
* elements for sorting and filtering) it can at times be a little tricky to get
|
|
|
4 |
* the next row based on another, while taking into account pagination,
|
|
|
5 |
* filtering, sorting etc.
|
|
|
6 |
*
|
|
|
7 |
* This function is designed to address exactly this situation. It takes two
|
|
|
8 |
* parameters, the target node, and a boolean indicating if the adjacent row
|
|
|
9 |
* retrieved should be the next (`true`, or no value) or the previous (`false`).
|
|
|
10 |
*
|
|
|
11 |
* @name fnGetAdjacentTr
|
|
|
12 |
* @summary Get the adjacent `dt-tag tr` element for a row.
|
|
|
13 |
* @author [Allan Jardine](http://sprymedia.co.uk)
|
|
|
14 |
*
|
|
|
15 |
* @param {node} nTr `dt-tag tr` element to get the adjacent element of
|
|
|
16 |
* @param {boolean} [bNext=true] Get the next (`true`), or previous (`false`)
|
|
|
17 |
* `dt-tag tr` element.
|
|
|
18 |
* @returns {node} `dt-tag tr` element or null if not found.
|
|
|
19 |
*
|
|
|
20 |
* @example
|
|
|
21 |
* $(document).ready(function() {
|
|
|
22 |
* var table = $('#example').dataTable();
|
|
|
23 |
*
|
|
|
24 |
* var n1 = $('#example tbody tr').eq(2)[0];
|
|
|
25 |
* var next = table.fnGetAdjacentTr( n1 );
|
|
|
26 |
* var prev = table.fnGetAdjacentTr( n1, false );
|
|
|
27 |
* } );
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
jQuery.fn.dataTableExt.oApi.fnGetAdjacentTr = function ( oSettings, nTr, bNext )
|
|
|
31 |
{
|
|
|
32 |
/* Find the node's position in the aoData store */
|
|
|
33 |
var iCurrent = oSettings.oApi._fnNodeToDataIndex( oSettings, nTr );
|
|
|
34 |
|
|
|
35 |
/* Convert that to a position in the display array */
|
|
|
36 |
var iDisplayIndex = $.inArray( iCurrent, oSettings.aiDisplay );
|
|
|
37 |
if ( iDisplayIndex == -1 )
|
|
|
38 |
{
|
|
|
39 |
/* Not in the current display */
|
|
|
40 |
return null;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/* Move along the display array as needed */
|
|
|
44 |
iDisplayIndex += (typeof bNext=='undefined' || bNext) ? 1 : -1;
|
|
|
45 |
|
|
|
46 |
/* Check that it within bounds */
|
|
|
47 |
if ( iDisplayIndex < 0 || iDisplayIndex >= oSettings.aiDisplay.length )
|
|
|
48 |
{
|
|
|
49 |
/* There is no next/previous element */
|
|
|
50 |
return null;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/* Return the target node from the aoData store */
|
|
|
54 |
return oSettings.aoData[ oSettings.aiDisplay[ iDisplayIndex ] ].nTr;
|
|
|
55 |
};
|