I would appreciate any help in ammending my script to add row call back function in database tables.
Using datatables I want to show the row number. I have found the code provided by @Pehmolelu in answer to a similar question but as this is my very first attempt with databasebles and javascript. I do not know enough about the syntax to put them together. The script I am current using:
<script> type="text/javascript">
$(document).ready(function(){
$('table').DataTable({
searching:true,
ordering:false,
paging:true,
"bLengthChange": false,
lengthMenu:[31],
})
});
</script>
This is what I think will show the row number provided by @Pehmolelu:
var index = iDisplayIndex +1;
$('td:eq(0)',nRow).html(index);
return nRow;
And I know it involves adding:
"fnRowCallback": function( nRow, aData, iDisplayIndex )
I have also tried this code, but this code shows a the row number for every row, so if there are a hundred rows it will show 1-100. What I want is for it to work with the pagination. So, if set to 20 rows per page each page would show row 1-20.
$(document).ready(function() {
var t = $('table').DataTable( {
"columnDefs": [ {
"searchable": false,
"orderable": false,
"targets": 0
} ],
"order": [[ 1, 'asc' ]]
} );
t.on( 'order.dt search.dt', function () {
t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i+1;
} );
} ).draw();
} );
I know it is very basic but I would really appreciate any help. Thanks