Forums › Forums › OroPlatform › OroPlatform – How do I? Questions › default for date in DatagridFilter
This topic contains 7 replies, has 4 voices, and was last updated by miken 9 years, 8 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- June 4, 2014 at 6:17 am #35753
Is it possible to set a default value for date filter in datagrids?
- CreatorTopic
- AuthorReplies
- June 4, 2014 at 6:52 am #35754
In my update method is do this:
123456if (!$entity) {$entity = $this->getManager()->createEntity();$entity->setCreatedAt(new \DateTime("now"));}This set the createdAt to the current datetime if a entity is created. In your case this would be the default you wanted.
June 5, 2014 at 1:07 am #35755Hi @mario-seidel!
Not sure that I got your question correctly.
Do you want to add some default filtering to grid? You can define default filters under
GRID_NAME.filters.default.YOUR_FILTER_COLUMN_NAME : { type: OPERATOR_VALUE, value: "value here"}
June 5, 2014 at 2:30 am #35756Sorry for the confusing question, i’ll give it a try:
I have got a datagrid like this:
columns:
purchaseDate:
label: purchase date
frontend_type: date
filters:
columns:
purchaseDate:
type: datetime
data_name: o.purchase_date
default:
purchaseDate:
value: ...?
When I enter the page the purchaseDate should be prefilled with a default value, for example today. And the datagrid should be already filtered by this value.
June 5, 2014 at 10:18 am #35757Please try this one:
12345678filters:default:purchaseDate:type: Oro\Bundle\FilterBundle\Form\Type\Filter\AbstractDateFilterType::TYPE_MORE_THANpart: Oro\Bundle\FilterBundle\Provider\DateModifierInterface::PART_VALUEvalue: { start: '{{2}}' }where {{2}} means “today”, all variables listed Oro\Bundle\FilterBundle\Provider\DateModifierInterface::VAR_ constants
June 10, 2014 at 3:20 am #35758That’s what I’m searching for.
Maybe a more comfortable access to this “function” would be great. But anyway, thank you, this helps alot.July 11, 2014 at 9:49 am #35759When setting the default like this is there a way to make the visible filter represent the default? The data is filtered correctly for me but the filter above it just says “Date: All” and if I change another filter it shows all dates in the data instead of keeping the default date I set in the datagird.yml
Thank you,
Mike
July 15, 2014 at 2:38 pm #35760on the latest dev-master the defaults are showing in the filter correctly now. Although when you clear the filter it refreshes and changes to “all” as expected but the results are still based on the original default filter.
- AuthorReplies
The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.