Why don't you use server side rendering ? table
<table id="yourTable" >
<thead>
<tr>
<th class="datatable-nosort">#</th>
<th>Invoice</th>
<th>Company</th>
<th class="datatable-nosort">Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
script
var t = $("#yourTable").DataTable({
scrollCollapse: true,
autoWidth: false,
responsive: true,
processing: true,
serverSide: true,
ajax: '{{ route('get.data') }}',
columns: [
{data: 'id'},
{data: 'invoice_no'},
{data: 'company'},
{data: 'actions'},
],
columnDefs: [
{
targets: "datatable-nosort",
orderable: false,
}
],
buttons: [
'copy','print','csv','pdf'
]
});
t.on('order.dt search.dt', function () {
t.column(0, {search: 'applied', order: 'applied'}).nodes().each(function (cell, i) {
cell.innerHTML = i + 1;
});
}).draw();