PHP code example of synergitech / fuel-datatables

1. Go to this page and download the library: Download synergitech/fuel-datatables library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

synergitech / fuel-datatables example snippets


class API extends Controller_Rest
{
  public function get_index()
  {
      $datatable = \SynergiTech\DataTables\DataTable::fromGet(\Model\YourModel::class);
      $datatable->setAllowedColumns([
         'id',
         'uuid',
         'name',
         'related_model.name',
         'created_at',
         'updated_at'
      ]);

      return $this->response($datatable->getResponse());
  }
}

$datatable->getQuery()
   ->where('id', ">", 0)
   ->related("group")
   ->where("group.name", "!=", "guests")
   ->related("another_relation");

$datatable->addRowFormatter(function ($model, $outputRow) {
    $outputRow['example'] = count($model->a_many_relation);
    return $outputRow;
});

$datatable->setEscapedColumns();

$datatable->setEscapedColumns()
    ->setRawColumns(['html_body']);

$datatable->setEscapedColumns(['id', 'slug']);

$datatable->setEscapedColumns([]);