What I want to do is that to create a serial number in the first column of the data table and if I am not using deferloading than the above code is working. BY Using this code data is comming but data table is not working. I am using Laravel at back end. Please comment If you need any other Information that I can provide to Solve the problem.
var table = $('#My Table').dataTable({
"processing": true,
"serverSide": true,
"ajax": "{!! route('Route') !!}",
"aaSorting": [[0, "desc"]],
"deferLoading": '{{ $total }}',
"columns": [
{data: 'col_1', name: 'name', 'sortable': true},
{data: 'col_2', name: 'name', 'sortable': true},
{data: 'col_3', name: 'name', 'sortable': true},
{data: 'col_4', name: 'name', 'sortable': true},
{data: 'col_5', name: 'name', 'sortable': true},
{data: 'col_6', name: 'name', 'sortable': true},
{data: 'col_7', name: 'name', 'sortable': true},
],
"lengthMenu": [
[5, 15, 20, -1],
[5, 15, 20, "All"] // change per page values here
],
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
var oSettings = table.fnSettings();
$("td:first", nRow).html(oSettings._iDisplayStart + iDisplayIndex + 1);
return nRow;
}
});
Javascript Error : Uncaught TypeError: Cannot read property 'fnSettings' of undefined I don't know what to do.
Well I have found this also works
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
var row = $(nRow);
row.attr("id", 'row'+aData['0']);
$("td:first", nRow).html(iDisplayIndex +1);
return nRow
Update your fnRowCallback to this