Large Data or 1 million Data Quick Load within few second | DataTables Server Processsing in Laravel

This post will show how to load big or large data like 10 lakh within a few seconds in Laravel using the DataTable Server process.



First Initializing Yajra laravel-datatables plugin

  • Run the following in the command/terminal,
  • Check composer.json

  • add the following code file to config/app.php

  • and finally, we publish the configuration, run the following line in the terminal,

    Code partially step by step for understanding(final code is given at the end)

    View part(showing the table)

    Import DataTables files

    Getting Data from Controller

  • in .env for database setup

  • In route

  • In controller

=====Final Codes======

3 main files

  1. view file welcome.blade.php
  2. route (web.php)
  3. controller/database query part (EmpController.php)
  • suppose view file(welcome.blade.php)

here some important features

  • serverSide: true, for enabling the Datatables Server processing
  • for retrieving or get the data from the database

              ajax: { url: ‘{{url(’emp_list’)}}’ },

  • to sent parameters or bariables to controller add data part in ajax

              ajax: { url: ‘{{url(’emp_list’)}}’, data: function (data) { data.params = { sac: “helo” } } },

  • to show data in empty <tbody></tbody> write

                columns: [
                  {data: “user_id”, className: ‘uid’},
                {data: “first_name”, className: ‘fname’},
                {data: “username”, className: ‘uname’},
                {data: “gender”, className: ‘gender’}

here user_id,first_name,username,gender are the column names of database table

                 className for giving a attribute to tbody td

  • in view tbody need to empty
  • make sure theader td total number is qual to columns data because datatable columns data is referreing theader td repectively.
  • give the table width=”100%” style so that table header and tbody width aligned perfectly
  • suppose route (web.php)

  • in controller EmpController.php


Share with:

Comments are closed.