Column editing
Transform values before they hit the client
After you obtain the data from the database, you may want to make changes before sending it to the client.
This is useful when you want to show part of an e-mail or do some custom calculations before the output is created.
| Id | Name | Unit Price |
|---|---|---|
| Loading… | ||
<?php
use Ozdemir\Datatables\Datatables;
use Ozdemir\Datatables\DB\SQLite;
Route::get('/ajax/edit-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->edit('id', function ($data) {
return '<a href="#'.$data['id'].'">#edit </a> '.$data['id'];
});
$dt->edit('UnitPrice', function ($data) {
return '$'.$data['UnitPrice'];
});
return $dt->generate();
});