Home > other >  Loading bulk data listing to DataTable using laravel
Loading bulk data listing to DataTable using laravel

Time:02-10

I'm trying to list bulk(million) data to DataTable, it takes a long time for reflecting the view page.

view JS

$.ajax({
  type:'POST',
  url: '/admin/secure/viewsupplier',
  headers: {
       'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
   },
  dataType: 'JSON',
  processData: false,
  contentType: false,
  success: function(response){

    var supplierTable = $('#supplier_table').DataTable({

    data: response,
    columns: [
       {'data':'name'},
       {'data':'email'},
       {'data':'phone'},
       {'data':'status'},
     ]

   });
  },
});

Controller

 public function viewsupplierRequest $request){
       
     $suppliers = DB::table('suppliers')->select('*')->cursor();
            
     return response()->json($suppliers);
 }

Db - PgSql

This will return 1 million supplier data for listing

I have tried get method also

    $suppliers = DB::table('suppliers')->get();

Blade

<table>
  <thead id="supplier_table">
    <tr>
      <th>Name</th>
      <th>Email</th>
      <th>Phone</th>
      <th>Status</th>
    </tr>
  </thead>
</table>

CodePudding user response:

  •  Tags:  
  • Related