How to include docstatus in standard filter?

For user added fields in a doctype, users can check “In Standard Filter”, then users can filter based on field.

For submitable doctypes, I need to include “docstatus” in standard filter so that I can filter draft/cancelled documents. How to include docstatus in standard filter?

1 Like

If you have the status field, it can be considered for this. Just add all status (draft, submitted, etc…) and check-in standard filter in field level.

@rk_root There is no explicit “status” field in the doctype.

When creating “Sales Invoice” doctype, if user checks “Is Submittable”, Frappe internally creates “docstatus” column.


I am not sure how to include this column in standard filter.

@ChillarAnand Please try adding docstatus as standard filter using the following code:

onload: function(listview){
const df = {
condition: “=”,
default: null,
fieldname: “docstatus”,
fieldtype: “Select”,
input_class: “input-xs”,
label: “Status”,
is_filter: 1,
onchange: function() {
listview.refresh();
},
options: [0,1,2],
placeholder: “Status”
};

//Add the filter to standard filter section
let standard_filters_wrapper = listview.page.page_form.find(‘.standard-filter-section’);
listview.page.add_field(df, standard_filters_wrapper);

//It will be a dropdown with options 1, 2, 3
//To replace it with Blank space, Draft, Submitted and Cancelled.
//First selecting the select option, may subject to changes as the the system
let doc_filter = document.querySelector(‘select[data-fieldname = “docstatus”]’)

//Add first option as blank space
doc_filter.options.add(new Option(), 0);

//Changing just options’ inner html for better user experience
doc_filter.options[1].innerHTML = ‘Draft’;
doc_filter.options[2].innerHTML = ‘Submitted’;
doc_filter.options[3].innerHTML = ‘Cancelled’;
}

I hope it works :slight_smile:

7 Likes

Thanks @ayushi_srivastava

Can it be added via “Custom Script”? This is a nifty solution to use everywhere.

Maybe someday within the framework we can have it added as a checkbox to enable docstatus to be seen in the standard filters

Yes!
Hopefully someday this functionality will be added to the framework. Until then this solution might help people.

1 Like

This is -fantastic-. Thank you so much.

I’ve been wanting this feature for a long, long time. I just added to one of my DocTypes, and it works perfectly. :100:

@ayushi_srivastava , you are my “ERPNext Hero Of The Month”.

4 Likes

Thank you @brian_pond :blush:

1 Like

Works great, thank you. I had issues copy & pasting it, as the quotes had to be converted to regular quotes. Heres the code using the preformatted text feature.

	onload: function(listview) {
		const df = {
			condition: "=",
			default: null,
			fieldname: "docstatus",
			fieldtype: "Select",
			input_class: "input-xs",
			label: "Status",
			is_filter: 1,
			onchange: function() {
				listview.refresh();
			},
			options: [0,1,2],
			placeholder: "Status"
		};

		//Add the filter to standard filter section
		let standard_filters_wrapper = listview.page.page_form.find('.standard-filter-section');
		listview.page.add_field(df, standard_filters_wrapper);

		//It will be a dropdown with options 1, 2, 3
		//To replace it with Blank space, Draft, Submitted and Cancelled.
		//First selecting the select option, may subject to changes as the the system
		let doc_filter = document.querySelector('select[data-fieldname = "docstatus"]');

		//Add first option as blank space
		doc_filter.options.add(new Option(), 0);

		//Changing just options’ inner html for better user experience
		doc_filter.options[1].innerHTML = 'Draft';
		doc_filter.options[2].innerHTML = 'Submitted';
		doc_filter.options[3].innerHTML = 'Cancelled';
	}
3 Likes