PHP code example of white-frame / dynatable

1. Go to this page and download the library: Download white-frame/dynatable 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/ */

    

white-frame / dynatable example snippets



use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use WhiteFrame\Dynatable\Dynatable;

class UserController extends Controller
  public function dynatable(Request $request)
  {
    // Get a query builder of what you want to show in dynatable
    $cars = Car::where('year', '=', 2007); // or Car::query() for all cars
    $columns = ['id', 'name', 'price', 'stock'];
    
    // Build dynatable response with your query builder, columns and all input from dynatable font end javascript
    $dynatable = Dynatable::of($cars, $columns, $request->all()));
    
    // ... Here you can customize the result and change columns handling with $dynatable (see example below)
    
    // Build the response and return to the table
    return $dynatable->make();
  }
}

$dynatable->column('price', function($car) {
    return number_format($car->price) . ' $';
});

$dynatable->column('actions', function($car) {
    return '<a href="/car/' . $car->id . '">View</a>';
});

$dynatable->sort('id', function($query, $mode) {
    return $query->orderBy('id', $mode == 'asc');
});

$dynatable->search(function($query, $term) {
    return $query->where('name', 'LIKE', '%' . $term . '%');
});

$dynatable->search('year', function($query, $term) {
    return $query->whereBetween('year', array($term - 5, $term + 5));
});