ssp
Datatables SSP class for server side scripting for PostgreSQL (uses ILIKE), (*1)
- May have columns for actions which are not in the database (eg.
@actions)
that can be used to display actions. The name should start with @.
<?php
$crud = [
'table_name' => 'students',
'fields' => [
'first' => 'text',
'middle' => 'text',
'last' => 'text',
'bday' => 'date',
'gender' => 'text'
]
];
$app->get('/'.$crud['table_name'].'/list', function ($request, $response, $args) use ($crud) {
$columns = [];
$count = 0;
foreach($crud['fields'] as $field => $data_type)
{
$column = ['db' => $field, 'dt' => $count++];
if ($data_type == 'date')
$column['formatter'] = function( $d, $row ) {
return date( 'F d, Y', strtotime($d));
};
else if ($data_type == 'number')
$column['formatter'] = function( $d, $row ) {
return '$'.number_format($d);
};
$columns[] = $column;
}
$columns[] = ['db' => 'id', 'dt' => $count++];
$columns[] = [
'db' => '@actions',
'dt' => $count++,
'formatter' => function ($d, $row ) use ($crud) {
return '
';
}
];
$ssp = DataTable\SSP::simple($request->getParams(), $this->db, $crud['table_name'], 'id', $columns);
return json_encode($ssp);
})->setName($crud['table_name'].'.list.json');