Open milsorm opened 3 years ago
Solution:
The question is if:
Solution with new descendants is also possible (and I am using it) but duplicates some code which is bad for maintanance with new versions.
I am using DataGrid together with Nextras ORM havily in new project for non-government organization so this is why I am creating new issues :-( Sorry for that.
You could simplify your solution by calling setCondition
(docs) on your dateFilter and provide custom template with setTemplate
(docs) like in this snippet:
$grid->addFilterDateRange('born', 'Year of birth')
// when working with Nextras/ORM (Nextras/Dbal), DbalCollection is first argument.
->setCondition(function(DbalCollection $source, $value) {
$qb = $source->getQueryBuilder();
$qb->andWhere('YEAR(column) = %s', /** here handle $value as you need */);
})
// use setTemplate, or use tempate block as can be seen in documentaion linked above
->setTemplate(/** path_to_your_year_date_range_filter_template.latte **/)
Good point, thanks. This is like my third bullet in question and it works. Thanks.
I am trying to solve limiting datagrid with people by range of their year of birth.
If I use
$col->setFilterDateRange()->setFormat( 'Y', 'yyyy' );
for limiting filter to year onColumnDateTime
, I have to enteryear+1
to "to" field, because internally inapplyFilterDateRange()
is used as DAY not YEAR with 23:59:59 time.Is it possibility to add
setCondition
or formatting forYEAR( column )
to check of this filter? I didn't find a way.Anyway
applyFilterRange()
cannot help because there is fix use ofcolumn <= int
and I cannot passYEAR( column)
to column.I am using Nextras ORM as data source.