Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatable server side php class for laravel

I want my datatables to process the data on the server side, I am referencing this example.

Server Side Example

However, the server side php class "ssp.class.php" given in this example uses core php with raw sql, I can not use it directly for laravel projects. Does anyone has reference to laravel way doing datatables. I don't want to use any packages at the moment though.

like image 297
Dipendra Gurung Avatar asked Jan 20 '26 17:01

Dipendra Gurung


1 Answers

UPDATED 14 Oct 2023

You can use syamsoul/laravel-datatable-ssp package..

[Link here][2]

  1. Open CLI and enter your app directory

  2. Run this command composer require syamsoul/laravel-datatable-ssp

  3. In your controller, you can follow the code below:

    <?php
    
    namespace App\Http\Controllers\Testing;
    
    use App\Http\Controllers\Controller;
    use SoulDoit\DataTable\SSP;
    use App\Models\User;
    
    class DatatableJsController extends Controller
    {
        public function index(SSP $ssp)
        {
            $ssp->setColumns([
                ['label' => 'ID',         'db' => 'id',         'formatter' => function ($value) {
                    return str_pad($value, 8, '0', STR_PAD_LEFT);
                }],
                ['label' => 'Email',      'db' => 'email'       ],
                ['label' => 'Username',   'db' => 'username'    ],
                ['label' => 'Created At', 'db' => 'created_at'  ],
            ]);
    
            $ssp->setQuery(function ($selected_columns) {
                return User::select($selected_columns);
            });
    
            return $ssp->response()->json();
        }
    }
    

This is working perfectly on Laravel 9 and above.

For more info, you can refer to the documentation site: https://info.souldoit.com/projects/laravel-datatable-ssp .

like image 78
Syamsoul Azrien Avatar answered Jan 23 '26 08:01

Syamsoul Azrien