Custom pre defined TableBuilder filters
Created 7 years ago by girvydasI am trying to do a custom table view in tab at the admin panel.
public function preview(ContactRepositoryInterface $contacts, ObjectsListTableBuilder $objectsListTableBuilder, ObjectModel $objectModel, $id) { $objectsListTableBuilder->setModel($objectModel); $objectsListTableBuilder->make(); $viewData['content'] = $objectsListTableBuilder->getTableContent(); return $this->view->make('module::admin/contacts/preview', $viewData); }
The problem is that I want to filter table with ‘predefined static’ filter using $id (ObjectID). How can I do that? I saw method ‘setTableEntries’ but it requires collection, not EloquentModel
I would add a setFoo
/ getFoo
method for a custom $foo
attribute on your model. Then you can use that value in the onQuerying
callback.
There is something done at
vendor/anomaly/streams-platform/src/Assignment/Table/AssignmentTableBuilder.php and vendor/anomaly/streams-platform/src/Assignment/Table/Command/SetDefaultProperties.php
Is this what are you talking about? It would be nice to have ability to set default filters in TableBuilder for example filter things by status/state/etc.
You can define your own table methods on table builders you've made. And onQuerying is a callback that's fired just after the query for the table gets started.
Check this out as an example: https://github.com/anomalylabs/store-module/blob/master/addons/anomaly/products-module/src/Http/Controller/Admin/ConfigurationsController.php#L60