1. Go to this page and download the library: Download ramondev/html-table-builder 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/ */
ramondev / html-table-builder example snippets
use Ramondev\HtmlTableBuilder\HtmlTableBuilder;
$table = new HtmlTableBuilder($users); // array or Eloquent Collection
return $table->render();
// In a controller
public function index()
{
$table = new HtmlTableBuilder(User::all());
return view('users.index', ['table' => $table]);
}
$table->each(function (HtmlTableBuilder $table, int $index, array $row) {
if ($row['is_flagged']) {
$table->setTableRowAttr(['class' => 'bg-red-50'], $index);
}
});
$table->escapeOutput(false); // disable escaping for ALL columns
$table->escapeOutput(false, 'status'); // disable escaping for just the "status" column
$table->escapeOutput(false, ['status', 'actions']); // disable escaping for several columns in one call
$table->setTableAttr(['class' => 'table table-striped', 'id' => 'users-table']);
$table->setTableHeadAttr(['class' => 'bg-gray-100']);
$table->setTableBodyAttr(['class' => 'divide-y']);
$table->setTableRowAttr(['class' => 'border-b']); // every row
$table->setTableRowAttr(['class' => 'bg-yellow-50'], 3); // just row index 3
$table->setTableDataAttr(['class' => 'px-4 py-2']); // every cell
$table->setTableDataAttr(['class' => 'font-bold'], 0, 'name'); // row 0, "name" column only
$table->paginate(15);
$table->setPaginationPageName('users_page'); // links become ?users_page=2