Star

Column hiding

Remove a column from output, keep its data

You may not want some columns in the database to appear in the output after you edit them in other columns.
The following example shows how easy it is to hide a column while still using its data internally.
Name Unit Price
Loading…
<?php
use Ozdemir\Datatables\Datatables;
use Ozdemir\Datatables\DB\SQLite;

Route::get('/ajax/hide-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->hide('id');

    $dt->edit('Name', function ($data) {
        return $data['Name']." (id: {$data['id']})";
    });

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