Custom Button on Report Builder View

I’m developing an app with a custom button in the header of the list view in a doctype.

The code I’m using in the doctypes workday_list.js file is as follows:

frappe.listview_settings['Workday'] = {
    onload: function (listview) {
        listview.page.add_inner_button(__("Bulk Add"), function () {
                // function here
        }
}

That works great for adding a button to the standard list view, but the button disappears if the user switches to a report view, even though workday_list.js clearly loads in both views.

How can I make the button persistent across both the list and report views?

Thanks

List View and Report View use different files
list_view.js and report_view.js
Both extend base_list.js

base_list.js loads the custom listview_settings code:

Then: list_view.js calls onload method from the custom settings in the setup_view method

But report_view.js on his setup_view method won’t call custom onload

Your option is to use refresh listener, which is called from base_list.js

In your workday_list.js

refresh: function (listview) {
    listview.page.add_inner_button(__("Bulk Add"), function () {
        // function here. Will Add it to List View and Report View
    });
}

Another Approach

You can create a Custom Report. Eg: Script Report and be able to customize the report view itself

Docs: Script Report

Example: [Tutorial] Script Report / Chart
Look for the .js filefrappe.query_reports["Script Report Tutorial"] = {

frappe.query_reports["Workday Report"] = {
    onload: function (report) {
        report.page.add_inner_button(__("Bulk Add"), function() {
            // function here. Will Add only to Report View
        });
    }
}
3 Likes

@JeansReal, you da man!