Dashboard filtering options

Hi,
I would like to ask if I could somehow present dashboard filters next to dashboard’s widgets. I suppose that I could create a widget including several fields as filters but I am looking for a generic mechanism that will allow users to apply very easily several filters at the same screen with widgets. Is that possible?

Thank you

Hi @papageor,

Do you mean usage of generic table filters in dashboard widgets?

Yes of course. Is that possible?

Hi @papageor,

It is possible, you can create widget with data source and filter. If you want to apply filter result to other widgets you need to create your custom event type and fire this event from your widget with filter. Event can be fired in filter handler void setAfterFilterAppliedHandler(AfterFilterAppliedHandler afterFilterAppliedHandler);. Other widgets can be subscribed to this event type to receive filter changes.

Regards,
Evgeny

Thank you Evgeny. Just wish to ask if there is already any demo project similar to my needs to start with.

Regards

Please check this example

@DashboardWidget(name = FilterAppliedWidget.CAPTION)
public class FilterAppliedWidget extends Screen {

    public static final String CAPTION = "Filter";
    
    @Inject
    private Events events;

    @Inject
    private Filter filter;

    @Inject
    private CollectionContainer collectionContainer;
    
    public static class FilterAppliedEvent extends ApplicationEvent {
        private List items;
        private Filter filter;

        public FilterAppliedEvent(List items, Filter filter) {
            super(items);
            this.items = items;
            this.filter = filter;
        }

        public List getItems() {
            return items;
        }

        public Filter getFilter() {
            return filter;
        }
    }

    @EventListener
    public void init(InitEvent event) {
        filter.setAfterFilterAppliedHandler(() -> {
            events.publish(new FilterAppliedEvent(collectionContainer.getItems(),filter));
        });
    }

}

More dashboard examles you can find in demo project GitHub - cuba-platform/dashboard-addon-demo: This demo application demonstrates the usage of Dashboard CUBA add-on..

Thank you for the provided sample.