Custom pre defined TableBuilder filters

girvydas - 3 weeks ago

I 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

ryanthompson - 3 weeks ago

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.

girvydas - 3 weeks ago

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.

ryanthompson - 3 weeks ago

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.