PHP code example of irpcpro / table-soft
1. Go to this page and download the library: Download irpcpro/table-soft 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/ */
irpcpro / table-soft example snippets
'providers' => [
...
...
\Irpcpro\TableSoft\ServiceProviders\TableSoftServiceProvider::class,
]
'aliases' => Facade::defaultAliases()->merge([
...
...
'TableSoft' => \Irpcpro\TableSoft\Facade\TableSoftFacade::class,
])->toArray(),
use TableSoft;
class HomeController extends Controller {
public function index(){
// get data from collection
$data = collect([ [..], [..], [..] ]);
// Or ..
// get data from models
$data = App\Models\Product::query();
// finally pass the data to TableSoft
$table = TableSoft::data($data);
}
}
$table->column('Title') // default key name = Title
$table->column('Title', 'columnTitle')
$table->column('Title', 'columnTitle:string') // default type column is string
$table->column('Title', 'columnTitle:string', 'sort') // default ASC
$table->column('Title', 'columnTitle:string', 'sort:asc')
$table->column('Price', 'price:int', 'sort', function($value){
return $value . '$';
});
$table->column('Price', 'price:int', function($value){
return $value . '$';
});
$table->column('Price', 'price:int', function($value){
return $value . '$';
})->searchable();
$table = $table->column('Price', 'price:int', function($value){
return $value . '$';
});
$table->searchable();
$table->setWidth(20);
$table->setWidth(20, 'px');
$table->rowCounter('row', 'row-name:string', function($val){
return $value;
});
$table->paginate(10);
$table->setCaching('id-name-table');
$data = Http::get('https://...../products');
$data = collect($data->json());
// get data
$data = Product::query();
// set table
$table = TableSoft::data($data);
$table = $table->column('Title', 'title:string', 'sort')->searchable();
$table = $table->column('Image', 'thumbnail:string', function($value){
return "<img src='$value'/>";
});
$table = $table->column('Description', 'description:string', 'sort:asc')->searchable();
$table = $table->column('Price', 'price:int', 'sort', function($value){
return $value . '$';
})->setWidth(50, 'px')->searchable();
$table = $table->rowCounter('row')->setWidth(20,'px');
$table = $table->setCaching('table-product4');
$table = $table->paginate(10);
// get table
$data = $table->get();
array:5 [▼
"head" => Illuminate\Support\Collection {#334 ▶}
"body" => Illuminate\Pagination\LengthAwarePaginator {#339 ▶}
"sort_fields" => Illuminate\Support\Collection {#316 ▶}
"query_params" => array:3 [▶]
"exists" => true
]
{
+title: "Description"
+name: "description"
+type: "string"
+sort: "sort"
+sortBy: "asc"
+value: "Description"
+width: null
+widthMeasure: null
+searchable: true
}
<table class="table table-bordered">
<thead>
<tr>
@foreach($data['head'] as $head)
<th width="{{$head->width ? $head->width.$head->widthMeasure : ''}}">{{$head}}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($data['body'] as $body)
<tr>
@foreach($body as $item)
<td width="{{$item->width ? $item->width.$item->widthMeasure : ''}}">{!! $item !!}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>