contributte / contributte/datagrid
Filter with default filter
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 296
- Forks
- 215
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I found an issue in filters. If I have date filter on column and it has default filter value. The problem appears if I clear filter input manually to empty string "". Datagrid does not set default filter in this case and also hides the reset button. So I am not able to reset grid to default filter. Here is the code. I am using it with Nextras ORM.
$grid->addColumnDateTime('closed', "$cDomain.date")
->setRenderer( function ( $item ) use ( $cDomain ) {
/** @var Task $item */
$title = $this->translator->translate("$cDomain.$item->state");
return '<span title="' . $title . '">' . $item->closed->format( 'j. n. Y' ) . '</span>';
})
->setTemplateEscaping( FALSE )
->setSortable()
->setFilterDate()
->setCondition( function ($fluent, $value) {
Debugger::log($value);
/** @var \Nextras\Orm\Mapper\Dbal\DbalCollection $fluent */
$start = DateTime::createFromFormat( 'j. n. Y', $value)->setTime( 0, 0, 0 );
$end = DateTime::createFromFormat( 'j. n. Y', $value)->setTime( 23, 59, 59 );
$fluent->getQueryBuilder()
->from('tasks', 'tasks')
->andWhere( 'tasks.closed > %dt', $start )
->andWhere( 'tasks.closed < %dt', $end );
});
$defaultDate = (new DateTime())->modify('- 14 Day');
$grid->setDefaultFilter(['closed' => $defaultDate->format( 'j. n. Y' )]);
It is not fatal but it has to be fixed via session.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with addColumnDateTime(), setFilterDate(), and setDefaultFilter() using the example in the report, then trace the behavior when the date input is cleared. Done means clearing the input does not lose the default filter and the reset button remains available so the grid can return to its default state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- full-stack
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100