Star

Add custom column

Extra columns for action buttons or anything else

When you retrieve data from the database, the columns may not be enough for special fields such as action buttons.
Define a custom field by adding a column. Search and sorting are disabled for these fields.
Id Name Unit Price Action
Loading…
<?php
use Ozdemir\Datatables\Datatables;
use Ozdemir\Datatables\DB\SQLite;

Route::get('/ajax/add-column', function () {
    $path = dirname(__DIR__).'/database/Chinook_Sqlite_AutoIncrementPKs.sqlite';

    $dt = new Datatables(new SQLite($path));
    $dt->query('Select TrackId as id, Name, UnitPrice from Track');

    $dt->add('action', function ($data) {
        return '<a href="#edit'.$data['id'].'">#edit </a> / '
             . '<a href="#del'.$data['id'].'">#delete </a>';
    });

    return $dt->generate();
});