Setting Report View default columns, width and # of displayed rows for all users

Hello!

I have set the default view as Report for Project doctype:

Is there any way I can assign the default columns, the columns’ width and number of displayed rows as well?

I’ve been skimming through report_view.js and I’m stuck trying to understand from which report entry it is pulling the defaults for this:

image

image

Considering that the user selected columns are saved, but not the width.

Thanks!!

Maybe just the default number of rows loaded by default?

Is there a quick adjustment that can be done? :eyes:

Ok, I found where the default pagination is set, works for report view as well:

/frappe-bench/apps/frappe/frappe/public/js/frappe/list/base_list.js

setup_defaults() {
	this.page_name = frappe.get_route_str();
	this.page_title = this.page_title || frappe.router.doctype_layout || __(this.doctype);
	this.meta = frappe.get_meta(this.doctype);
	this.settings = frappe.listview_settings[this.doctype] || {};
	this.user_settings = frappe.get_user_settings(this.doctype);

	this.start = 0;
	this.page_length = 20;

If someone has any ideas on how to adjust the default columns and their respective width for a particular doctype, please share it :slightly_smiling_face:

Solved this by patching frappe-bench/apps/frappe/frappe/public/js/frappe/views/reports/report_view.js version 15.12.0, replacing function setup_defaults() by:

setup_defaults() {
	super.setup_defaults();
	this.page_title = __("Report:") + " " + this.page_title;
	this.view = "Report";

	const route = frappe.get_route();
	if (route.length === 3) {
		let defRpt = route[1] + " Default";
		return frappe.db.exists("Report", defRpt)
			.then((x) => {
				if (x) {
					route.push(defRpt);
				}
				return this.do_setup_defaults(route);
			});
	} else {
		return this.do_setup_defaults(route);
	}
}

do_setup_defaults(route) {
	if (route.length === 4) {
		this.report_name = route[3];
	}

	if (this.report_name) {
		return this.get_report_doc().then((doc) => {
			this.report_doc = doc;
			this.report_doc.json = JSON.parse(this.report_doc.json);

			this.filters = this.report_doc.json.filters;
			this.order_by = this.report_doc.json.order_by;
			this.add_totals_row = this.report_doc.json.add_totals_row;
			this.page_title = __(this.report_name);
			this.page_length = this.report_doc.json.page_length || 20;
			this.order_by = this.report_doc.json.order_by || "modified desc";
			this.chart_args = this.report_doc.json.chart_args;
		});
	} else {
		this.add_totals_row = this.view_user_settings.add_totals_row || 0;
		this.chart_args = this.view_user_settings.chart_args;
	}
	return this.get_list_view_settings();
}

Customize a doctype, View Settings, Default View to Report. Adjust that doctype’s default report view (columns to display via Pick Columns menu) and Save As custom report named “< doctype > Default”, e.g. “Work Order Default”. Then this report will be shown by default for that doctype for all users.

And to prevent the default fields (name, docstatus) from sticking to the beginning of the report, in the same file, function set_fields(), move the line:

["name", "docstatus"].map((f) => this._add_field(f));

down to be the last line before the final one in that function:

this.set_default_fields();

Since these changes modify core Frappe code, it will be overwritten by the next update. So, need to find a way to restore them (git stash/pop?) and also copy to production.

1 Like