ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Dynamic Custom Filter in Reports

customization

#1

Is there a way I can add a custom ‘filter’ dynamically to a ‘Reports’ screen after the page has loaded? I want to add a new filter after I allow the user to select additional columns for the report. Any help will be appreciated. TIA


#2

Create new Report and save it with the required filter. Should that help?


#3

@umair Thanks for responding…
My case is, I’m creating a report using script report which will have around 5 primary columns that will be listed out as soon as the report loads. Then I give the user an option to add more columns to the report dynamically from a list of columns listed out to him… This is to provide the user ability to customise the same report as per his requirement… In my use case the same report should refresh based on the selected columns
So I was planning to send this selected list as Data to a new filter created on the fly so that it can be applied to the report.
My data is ready but I’m not sure how to append to the existing filter on the fly


#4

@umair Can I do a frappe.set_route to the same report from where I’m calling it? If that is a possibility I can set the filter using route_options.
The report is not getting refreshed when I do it this way. Any ideas on how I should go about this?


#5

Check this out https://github.com/frappe/frappe/blob/develop/frappe/public/js/frappe/views/reports/query_report.js

You can just push new filters in the filters array and then refresh the query report. You can access the query_report object by using frappe.query_reports[report_name]


#6

frappe.query_report.load(); did the trick
Thanks @netchampfaris for helping find the right direction


#7

The solution that worked for me is:
I placed a filter on the report, of type Data (hidden as the user does not have to select it) and upon selection of required fields I add it to the above mentioned filter using the route_options in the frappe.set_route method.
eg:

frappe.set_route(“query-report”,“ReportName”,{“filtername”: “data to be sent to filter”}

This set the new value to my filter but did not refresh my report. This problem got resolved using

frappe.query_report.load();


#8

Where can set the filters in query_report.js or what ?


#9

When you create a script report, you will have .js and .py files created for this report (in their respective folder). You can set the filters in the .js file for the report you have created


#10

@umair @netchampfaris
Hi,
Is there any way to add placeholder to my custom filter ?


#11

@farqalit yes you can, check this: