Tree filter and grouped rows

Choose nested values in a tree (industries) and show a heading row per value of a field (country).

The code

app/src/Controllers/ClientController.php – TreeFilter on a nested model whole file
protected function defineFilters(): FilterCollection
{
return FilterCollection::create()
->add(TextFilter::create('Query', 'Search')
->apply(fn (DataList $list, $value) => $list->filterAny([
'Name:PartialMatch' => $value,
'City:PartialMatch' => $value,
])))
->add(TreeFilter::create('Industry', 'Industry')
->options(fn () => Industry::get()->filter('ParentID', 0))
->apply(function (DataList $list, array $ids) {
// A chosen industry includes the ones below it.
$all = [];
foreach (Industry::get()->byIDs($ids) as $industry) {
$all = array_merge($all, $industry->withDescendantIDs());
}
return $list->filter('IndustryID', $all ?: [0]);
}))
->add(SelectFilter::create('Active', 'Active')
->options(['1' => 'Active', '0' => 'Inactive'])
->apply(fn (DataList $list, $value) => $list->filter('IsActive', (int) $value)));
}
app/src/Controllers/ClientController.php – groupBy() whole file
protected function defineColumns(): ColumnCollection
{
return ColumnCollection::create()
->make('Name', 'Client')->link('view/{ID}')->sortable()->end()
->make('City', 'City')->sortable()->end()
->make('Industry.FullTitle', 'Industry')->end()
->make('Projects.Count', 'Projects')->end()
->make('IsActive', 'Active')->format(fn ($value) => $value ? 'yes' : 'no')->end()
->lastViewed('Last viewed')->optional()->end()
->groupBy('Country', 'No country');
}
app/src/Controllers/TaskController.php – Tasks grouped by project whole file
protected function defineColumns(): ColumnCollection
{
return ColumnCollection::create()
->make('Title', 'Task')->end()
->make('StatusLabel', 'Status')->type('badge')->end()
->make('DueDate', 'Due')
->format(fn ($value) => $value ? date('d M Y', (int) strtotime((string) $value)) : '')
->sortable()->end()
->make('Assignee.Name', 'Assignee')->end()
->groupBy('Project.Title', 'Without project');
}