Scroll to highlighted row
Scroll to highlighted row
I am building the following scrolling table (1.7 Beta 3, Firefox):
[code]
$('ssTbl').dataTable({
"aoColumnDefs": [ { "bSortable": false, "aTargets": [1,2,3,4,5,6] },
{ "bVisible": false, "aTargets": [7] }
],
"aaSorting": [],
"bAutoWidth": true,
"bJQueryUI": true,
"sScrollX": "99%",
"sScrollY": "500px",
"sDom":..... /* Toolbar with First, Prev, Next, Last links here... */
});
[/code]
The toolbar allows the user to go through each row, one-by-one with Prev and Next buttons and it displays data to the user related to that record. The function also highlights the selected row.
When the user wants to use the toolbar and the row he selects is not in the table view (scroll required), then I would like to be able to have the table scroll to that row. If I set the _iDisplayStart to the row number, all of the preceding rows are no longer shown in the table, and that is not really an option.
Is there something like Java's JComponent.scrollRectToVisible() already implemented for this case?
Thanks - John
[code]
$('ssTbl').dataTable({
"aoColumnDefs": [ { "bSortable": false, "aTargets": [1,2,3,4,5,6] },
{ "bVisible": false, "aTargets": [7] }
],
"aaSorting": [],
"bAutoWidth": true,
"bJQueryUI": true,
"sScrollX": "99%",
"sScrollY": "500px",
"sDom":..... /* Toolbar with First, Prev, Next, Last links here... */
});
[/code]
The toolbar allows the user to go through each row, one-by-one with Prev and Next buttons and it displays data to the user related to that record. The function also highlights the selected row.
When the user wants to use the toolbar and the row he selects is not in the table view (scroll required), then I would like to be able to have the table scroll to that row. If I set the _iDisplayStart to the row number, all of the preceding rows are no longer shown in the table, and that is not really an option.
Is there something like Java's JComponent.scrollRectToVisible() already implemented for this case?
Thanks - John
This discussion has been closed.
Replies
You just need to determine upon next/previous whether or not the new row is fully visible.
And for those of you, who don't have time to figure out how to use the scroller:
[code]
var scroller = oTable.fnSettings().nTable.parentNode;
$(scroller).scrollTo( object, 1 );
[/code]
- object - in my case is the to which i want to scroll
- oTable - datatable.
Where do the lines in przemek's post go? Am I missing an initialization?
And if my selected row has class renamesel, would this be correct?
[code]$(scroller).scrollTo( 'tr.renamesel', 1 );[/code]
Many thanks,
John
With that in, this code works:
[code]
$(document).ready(function() {
var oTable = $('#renametab1').dataTable();
$('tbody tr td:nth-child(2)', $('#renametab1')[0]).editable('setsavecust.php', {
"callback": function( sValue, y ) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[1] );
},
"submitdata": function ( value, settings ) {
return {
"row_id": this.parentNode.getAttribute('id'),
"column": oTable.fnGetPosition( this )[2]
};
},
"height": "13px"
} );
var scroller = oTable.fnSettings().nTable.parentNode;
$(scroller).scrollTo( 'tr.renamesel', 1);
} );
[/code]