Table builder
A Laravel library to build tables easily, which interacts with a lightweight js builder and builds data from Eloquent Object-Relational Mapping with database tables. Table can also load static data. Current version: 2.3.0. Project on GitHub. Project on Packagist. This demosite sources available here.
Table inited with static data
Controller method for view
In your controller create an instance of TableBuilderHelper and pass the variable to the view.
$oTable = TableBuilderHelper::initTable('tabtest2', route("tableload2"));
$oTable->addColumn(TableBuilderHelper::initColumn('data', 'country', array(
'title' => 'Country',
'sortable' => true,
'defaultOrder' => 'asc'
)));
$oTable->addColumn(TableBuilderHelper::initColumn('data', 'code', array(
'title' => 'Code',
'sortable' => true
)));
return view('template', ['oTable' => $oTable]);
Insert following in blade template: {!! $oTable->output() !!}
Controller method for data:
public function loadTable2(Request $request)
{
$oTable = TableBuilderHelper::initDataBuilder($request);
// gets static data and builds datas
$countries = Countries::getList();
shuffle($countries);
foreach ($countries as $item) {
$oTable->addLine($item);
}
// builds a search function for search field
$wherefn = function ($data) {
return (mb_stripos($data['code'], $this->searchTerm) !== false) ||
(mb_stripos($data['country'], $this->searchTerm) !== false);
};
// attach search function to databuilder
$oTable->setSearchFunction($wherefn);
// return data for table
return $oTable->output();
}