Forums › Forums › OroPlatform › OroPlatform – How do I? Questions › OroCalendar and Filters
This topic contains 8 replies, has 3 voices, and was last updated by Artem Liubeznyi 7 years, 3 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- September 29, 2016 at 12:27 am #36324
Hi,
I want to use filters like ones used with datagrid but with orocalendar. Can you give me some hints for starting?
Thanks!
- CreatorTopic
- AuthorReplies
- September 29, 2016 at 5:50 am #36325
Hi
Are we talking about /calendar/default page ?
What properties of calendar do they must filter ?September 29, 2016 at 5:55 am #36326Hi
It’s not about the oro default calendar events. I’ve created my custom event entity and it has some properties which i need to filter. For example if we refer to orocalendar events i need to filter events by description containing some “text”!
Thanks
September 29, 2016 at 7:27 am #36327As i understood are you need to create datagrid for your custom entity ?
September 29, 2016 at 8:48 am #36328No! I have developed my own calendar bundle with my custom evenst entity. The calendar view is working good. What i need now is to add some filters for the calendar view to filter the events. I was thinking to use the filters that shows with a datagrid in a index template, but instead of filtering datagrid collection, they must filter the calenndar events collection.
September 29, 2016 at 10:34 pm #36329To understand better i added a print screen:
Looking at this picture, i need to be able to filter calendar events when i change a filter from the grid filters.
Thanks!
October 3, 2016 at 3:54 am #36330Hi,
I understood what you want.
Replace _onFilterUpdated function of filters manager following code:
JavaScript12345678910111213141516_onFilterUpdated: function(filter) {var activeFilters = [];_.each(this.filters, function(filter, name) {if (filter.enabled && !_.isObject(filter.value.value) && filter.value.value) {activeFilters.push({name: name, value: filter.value.value});}}, this);if (activeFilters.length > 0) {mediator.trigger('current_active_filters', activeFilters);}this._resetHintContainer();this.trigger('updateFilter', filter);}Further call following code from here:
JavaScript1mediator.on('setCalendarCollection', this.setCalendarCollection, this);and add this new function to calendar-view.js:
JavaScript123456setCalendarCollection: function (response) {this.collection.reset(response);this.updateEventsLoadedCache();this.updateEventsWithoutReload();}add this code to calendar view page:
JavaScript12345678910111213141516171819202122<script type="text/javascript">require(['oroui/js/mediator', 'oroui/js/widget-manager', 'underscore'],function(mediator, widgetManager, _) {mediator.bind('current_active_filters', function(filters) {var url = '{{ path('oro_api_get_calendarevents', { calendar: entity.id, start: startDate|date('c'), end: endDate|date('c'), subordinate: true})|raw }}';_.each(filters, function(filter) {url = url + '&' + filter.name + '=' + filter.value;});$.ajax({url: url,type: 'GET',success: function(response) {mediator.trigger('setCalendarCollection', response);},error: function(xhr) {}});});});</script>How it works. When filter is changed filter manager call current_active_filters trigger with all active filters, further calendar view calls api and get all calendar events, after that calendar events array go to setCalendarCollection event and update collection. Also you should modify api get function to filter your calendar event. This is good base to start, for now change month arrows don’t work, i think better save your active filters inside calendar-view.js and call api from these and somehow handle buttons with this filters.
October 3, 2016 at 10:51 pm #36331Thank you Mike! Indeed is a good base to start. Your code works like charm!
December 7, 2016 at 1:10 pm #36332@bosumflici
Out of sheer product curiosity: Why would you develop a custom calendar bundle? To me it looks like a tool for project management, a Gantt chart template. What were your use cases?
- AuthorReplies
The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.