PHP code example of bubooon / simple-tables

1. Go to this page and download the library: Download bubooon/simple-tables 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/ */

    

bubooon / simple-tables example snippets


{!! $simpletable ?? '' !!}

$provider = new BuilderDataProvider((new User)->newQuery());
$grid = new SimpleTable($provider,['id','email','created_at','updated_at']);
echo $grid->render();

$provider = new BuilderDataProvider($query, [
    'pagination' => [
        'pageSize' => 25
    ],
    'fieldsList' => ['id', 'email', 'status', 'age', 'created_at'],
    'sort' => [
        'id' => 'DESC'
    ]
]);

$provider->filter('email', 'email', 'like'); // serach substring
$provider->filter('was_found', 'was_found'); // strict search
$provider->filter('transaction_id', 'transaction_id', 'is_null'); //0 - IS NULL, 1 - IS NOT NULL, null - nothing

$fields = ['email', 'description', 'first_name', 'last_name'];
$provider->fullSearch($fields);

if ($last_update = request('date_created')) {
    switch ($last_update) {
        case 1:
            $provider->whereRaw('str_to_date(result.response ->> "$**.LastUpdatedDate", \'["%d/%m/%Y %T"]\') > now() - INTERVAL 1 WEEK');
            break;
        case 2:
            $provider->whereRaw('str_to_date(result.response ->> "$**.LastUpdatedDate", \'["%d/%m/%Y %T"]\') > now() - INTERVAL 1 MONTH');
            break;
    }
}

$table = new SimpleTable($provider, [
    'id', //just show value with defautl sorts by this column
    [
        'attribute' => 'email',
        'sort' => false, //remove ability to sort by this column
        'filter' => true, //add input[type=text] filter for this column 
        'label' => 'User email', //set custom header of column,
        'style' => 'width:250px' //css style for column
    ],
    [
        'attribute' => 'status',
        'filter' => [ //add dropdown filter
            '' => '',
            1 => 'Available',
            0 => 'Not available'
        ],
        'value' => function($row){
            return $row->status ? 'available' : 'not available';
        }
    ]
], [
    'fullSearch' => true, //add full search field
    'pageSizes' => [10, 25, 50, 100], //set available sizes of page,
    'showFooter' => false //hide table footer
]);

php artisan vendor:publish --tag=simple-tables