I need to scroll until specific row in my datatable like this:
https://datatables.net/extensions/scroller/examples/initialisation/api_scrolling.html
This is my code:
<script src="js/jquery-1.12.4.js"></script>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/scroller/1.4.2/js/dataTables.scroller.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/form-builder.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
....
<script>
$(document).ready(function() {
tableEntityList = $('#accentityListTable').DataTable({
"ordering": false,
"scrollY":"120px",
"scrollCollapse": true,
"paging":false,
"dom":'<<"top"i>ft>',
"deferRender":true,
"scroller":true,
"columnDefs": [
{"targets": [ 0 ],"visible": false}
],
"createdRow": function( row, data, dataIndex ) {
if ( data[ 3 ] == "Inp" )
$(row).css('color', 'green')
else
$(row).css('color', 'red')
if ( data[7] > 0 ) $(row).css('font-weight', 'bold')
},
"initComplete": function () {
alert("first");
this.api().row( 2 ).scrollTo();
alert("second");
}
});
})
</script>
The first alert appears:
alert("first");
But the second one, doesnt:
alert("second");
What i am doing wrong?
Thanks.
I think the problem is probably with your use of 'this'. In this case, I think it actually references the callback function, and not the DataTable. I'm not sure if you could pass it as a parameter to the callback function somehow, but if you create a reference to the DataTable outside the callback function's scope, you can access it by that variable.
Kindly replace with the below initComplete function. It will work.
Note: 2 represents n-1 targetted row
I think instead of "scrollY":"120px", it should be "scrollY":"120". try without px.