I have a list of users and I’m trying to set up a default filter on the createdAt
attribute to get by default the users created in the last month rather than all the users at once.
Here’s my current attempt:
EntityUser.php
#[ORMColumn(name: 'creation_date', type: 'datetime', nullable: true)]
private ?DateTime $createdAt = null;
UserAdmin.php
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper->add('createdAt', DateTimeRangeFilter::class, [
'field_type' => DateTimeRangePickerType::class,
])
...
}
protected function configureDefaultFilterValues(array &$filterValues): void
{
$filterValues['createdAt'] = [
'value' => [
'start' => (new DateTime())->modify('-1 month')->format('M d, Y, h:i:s a'),
'end' => (new DateTime())->format('M d, Y, h:i:s a'),
],
];
}
New contributor
Emeric Sailly is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.