Dynamic Custom Filter in Reports

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

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

@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

@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?

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]

2 Likes

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

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();

1 Like

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

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

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

@farqalit yes you can, check this:

if I want to add pos_profile as filter and want to set current user’s pos profile(current pos profile) as default, what should I do?
It’s not a built in report. I’m trying to do this in a custom report which I created in a custom app. (path to this report from frappe-bench folder like: /frappe-bench/apps/bio/bio/bio/reports/item_wise_report)

Ex-
“filters”: [
{
fieldname:“company”,
label: __(“Company”),
fieldtype: “Link”,
options: “POS Profile”,
default: GET CURRENT POS PROFILE QUERY*
},