Classes (0) | Namespaces (3) |
Properties (1) | Static properties (1) |
Methods (4) | Static methods (0) |
Events (0) |
Properties (1) | Static properties (1) |
Methods (4) | Static methods (0) |
Events (0) |
Scroller is a virtual rendering plug-in for DataTables which allows large datasets to be drawn on screen every quickly. What the virtual rendering means is that only the visible portion of the table (and a bit to either side to make the scrolling smooth) is drawn, while the scrolling container gives the visual impression that the whole table is visible. This is done by making use of the pagination abilities of DataTables and moving the table around in the scrolling container DataTables adds to the page. The scrolling container is forced to the height it would be for the full table display using an extra element.
Note that rows in the table MUST all be the same height. Information in a cell which expands on to multiple lines will cause some odd behaviour in the scrolling.
Scroller is initialised by simply including the letter 'S' in the sDom for the table you want to have this feature enabled on. Note that the 'S' must come AFTER the 't' parameter in sDom.
Key features include:
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | oDT | object | DataTables settings object | ||
2 | oOpts | object | Optional | {} | Configuration object for FixedColumns. Options are defined by Scroller.oDefaults |
$(document).ready(function() { $('#example').dataTable( { "sScrollY": "200px", "sAjaxSource": "media/dataset/large.txt", "sDom": "frtiS", "bDeferRender": true } ); } );
Calculate and store information about how many rows are to be displayed in the scrolling viewport, based on current dimensions in the browser's rendering. This can be particularly useful if the table is initially drawn in a hidden element - for example in a tab.
Calculate the row number that will be found at the given pixel position (y-scroll)
Calculate the pixel position from the top of the scrolling container for a given row
Calculate the row number that will be found at the given pixel position (y-scroll)
Calculate and store information about how many rows are to be displayed in the scrolling viewport, based on current dimensions in the browser's rendering. This can be particularly useful if the table is initially drawn in a hidden element - for example in a tab.
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | bRedraw | bool | Optional | true | Redraw the table automatically after the recalculation, with the new dimentions forming the basis for the draw. |
$(document).ready(function() { // Make the example container hidden to throw off the browser's sizing document.getElementById('container').style.display = "none"; var oTable = $('#example').dataTable( { "sScrollY": "200px", "sAjaxSource": "media/dataset/large.txt", "sDom": "frtiS", "bDeferRender": true, "fnInitComplete": function (o) { // Immediately scroll to row 1000 o.oScroller.fnScrollToRow( 1000 ); } } ); setTimeout( function () { // Make the example container visible and recalculate the scroller sizes document.getElementById('container').style.display = "block"; oTable.fnSettings().oScroller.fnMeasure(); }, 3000 );
Calculate the row number that will be found at the given pixel position (y-scroll)
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | iPixels | int | Offset from top to caluclate the row number of |
Row index
$(document).ready(function() { $('#example').dataTable( { "sScrollY": "200px", "sAjaxSource": "media/dataset/large.txt", "sDom": "frtiS", "bDeferRender": true, "fnInitComplete": function (o) { // Find what row number is at 500px alert( o.oScroller.fnPixelsToRow( 500 ) ); } } ); } );
Calculate the pixel position from the top of the scrolling container for a given row
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | iRow | int | Row number to calculate the position of |
Pixels
$(document).ready(function() { $('#example').dataTable( { "sScrollY": "200px", "sAjaxSource": "media/dataset/large.txt", "sDom": "frtiS", "bDeferRender": true, "fnInitComplete": function (o) { // Find where row 25 is alert( o.oScroller.fnRowToPixels( 25 ) ); } } ); } );
Calculate the row number that will be found at the given pixel position (y-scroll)
Name | Type | Attributes | Default | Description | |
---|---|---|---|---|---|
1 | iRow | int | Row index to scroll to | ||
2 | bAnimate | bool | Optional | true | Animate the transision or not |
$(document).ready(function() { $('#example').dataTable( { "sScrollY": "200px", "sAjaxSource": "media/dataset/large.txt", "sDom": "frtiS", "bDeferRender": true, "fnInitComplete": function (o) { // Immediately scroll to row 1000 o.oScroller.fnScrollToRow( 1000 ); } } ); // Sometime later on use the following to scroll to row 500... var oSettings = $('#example').dataTable().fnSettings(); oSettings.oScroller.fnScrollToRow( 500 ); } );