Middlewares in Table Generator
allow you to modify table data, structure, or appearance before rendering. You can apply multiple middlewares to a table by passing them as an array to TableGenerator
.
Applying Multiple Middlewares
use Ucscode\HtmlComponent\TableGenerator\TableGenerator;
use Ucscode\HtmlComponent\TableGenerator\Adapter\ArrayAdapter;
// Assume these middleware classes already exist
$formatMiddleware = new FormatCellMiddleware();
$checkboxMiddleware = new CheckboxMiddleware();
$removeColumnMiddleware = new RemoveColumnMiddleware(['password']);
$adapter = new ArrayAdapter($data);
$tableGenerator = new TableGenerator($adapter, [
$formatMiddleware,
$removeColumnMiddleware,
$checkboxMiddleware
]);
echo $tableGenerator->render();
Middleware Execution Order
Middlewares execute in the order they are added. In the example above:
FormatCellMiddleware
modifies cell values.RemoveColumnMiddleware
removes unwanted columns likepassword
.CheckboxMiddleware
add checkboxes to each table row.
Dynamically adding Middlewares
You can add more middleware after the TableGenerator
instance has been created. However, you should remember to regenerate the table structure as they are not automatically applied
$tableGenerator
->addMiddleware(new ActionButtonsMiddleware())
->addMiddleware(new BootstrapStyleMiddleware())
;
$tableGenerator->regenerate();
echo $tableGenerator->render();