platform
platform copied to clipboard
Implement a simplified direct filtering syntax on a table
Hi, I recently saw that in the table layout, we can now customize the filters ourselves for our tasks, by:
TD::make('example')->filter(Input::make())
And it's really great, but over time I ran into an inconvenience.
Therefore, I decided it for myself, but perhaps the idea of such a solution will be useful to the project (I do not make a pull request yet, since this implementation is still at the testing stage and not completed).
The essence of the problem lies in the fact that sometimes we have data that we do not get directly from the model on which we build the table, but we form it through the ->render() method, so we want to filter it in a special way.
Let's take the following example:
TD::make('user', __('User'))
->filter(Relation::make('users')
->fromModel(User::class, 'name')
->multiple()
)
->render(function (Alarm $alarm) {
return new Persona($alarm->user->presenter());;
}),
We will have to copy the code that we put in the ->filter() method from the layout to the layout where we display users, which in my opinion, is not very convenient.
Also, it is currently not possible to place multiple fields in the filter, such as Relation and RadioButton, if we want to provide more filtering flexibility for the end user.
Another not unimportant fact is that by placing code in the ->filter() method, we increase the volume of instructions and the code becomes less readable.
My solution is as follows:
Leave the functionality that is currently present, but add the possibility of the following syntax:
TD::make('user', __('User'))
->filter( UserFilter::class)
->render(function (Alarm $alarm) {
return new Persona($alarm->user->presenter());;
}),
This will allow:
- reuse and group recurring filter templates for a specific position.
- Keep the convenience and readability of the code when using specific filters in tables
- Add completely different fields to filter by the required field and process them as we need in the
UserFilter::class
In the screenshot, I gave an example of what it can allow us to end up with
It doesn't matter to me who implements it, I or someone else. It just seems to me that this is what is currently missing in direct filtering in tables, thanks!