How to implement DataTables server-side in laravel

12. September 2016 Intermediate, Laravel 14
How to implement DataTables server-side in laravel

Hello everyone, welcome back! This post is an extension to a previous post on DataTables, where we initiated data tables with basic initialization. As many readers suggested to make a tutorial on DataTables server-side am doing this and I strongly recommend you to go through the previous post before proceeding as I do not explain in detail about integrating DataTables, I’ll just extend the previous post with a server-side example.

Previous post: How to implement data tables in laravel

Working Demo      Project on Github

 

For using DataTables server-side operations we use yajra data tables plugin. The plugin can be found at github.com/yajra/laravel-datatables.

Initializing Yajra laravel-datatables plugin

We need to install yajra package using composer for DataTables server-side implementation.

Run the following the command to install it,

composer require yajra/laravel-datatables-oracle:~6.0

or else add the following code to composer.json file and run composer install

and add DataTables to providers list /config/app.php

and finally, we publish the configuration,

php artisan vendor:publish --tag=datatables

View part ( showing the table )

Here we show all the data in a table, we use the same data from the previous example,

the class names used above for table are as suggested by datatables.net/examples/styling/material.html

 

Working Demo      Project on Github

DataTables js part

I use some javascript to initialize DataTables, process server-side requests.

I am using material design here to implement this DataTables server-side implementation, for achieving the material design, I add a  few classes to the data table mdl-data-table__cell--non-numeric.

Function to retrieve data from the database

As we see in the above script, the ajax call routes to serverSide, here is the logic for it,

We used the same model function from the previous tutorial, please look there.

Datatables server-side implementation in laravel - justlaravel.com
Datatables server-side implementation in laravel – justlaravel.com

 

Working Demo      Project on Github



14 thoughts on “How to implement DataTables server-side in laravel”

Leave a Reply