Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multiple buttons (dropdown) in listview row #26162

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Nihantra-Patel
Copy link
Contributor

@Nihantra-Patel Nihantra-Patel commented Apr 25, 2024

fixes: #26026

Documentation Link: https://frappeframework.com/docs/user/en/api/list

Before:

image

After:

multiple_button_listview.mov

Listview code structure:

frappe.listview_settings["ToDo"] = {
	hide_name_column: true,
	add_fields: ["reference_type", "reference_name"],

	button: {
		show: function (doc) {
			return doc.reference_name;
		},
		get_label: function () {
			return __("Open", null, "Access");
		},
		get_description: function (doc) {
			return __("Open {0}", [`${__(doc.reference_type)}: ${doc.reference_name}`]);
		},
		action: function (doc) {
			frappe.set_route("Form", doc.reference_type, doc.reference_name);
		},
	},
	dropdown_button: {
		get_label: __("Dropdown"),
		buttons: [
			{
				get_label: __("Button 1"),
				show: function(doc) {
					return true;
				},
				get_description: function(doc) {
					return "Open Button 1 " + doc.reference_name;
				},
				action: function(doc) {
					frappe.msgprint("Dropdown Button 1 Clicked " + doc.reference_name);
				}
			},
			{
				get_label: __("Button 2"),
				show: function (doc) {
					return doc.status != "Closed";
				},
				get_description: function(doc) {
					return "Open Button 2 " + doc.reference_name;
				},
				action: function(doc) {
					frappe.msgprint("Dropdown Button 2 Clicked " + doc.reference_name);
				}
			},
			{
				get_label: __("Button 3"),
				show: function (doc) {
					return doc.status !="Cancelled";
				},
				get_description: function(doc) {
					return "Open Button 3 " + doc.reference_name;
				},
				action: function(doc) {
					frappe.msgprint("Dropdown Button 3 Clicked " + doc.reference_name);
				}
			},
		]
	}
};

Edit:

Earlier, when I used to put a condition inside show, when I clicked on button 3, the action of button 1 was performed. So I fixed the button action. Now when you click on the button, the same action will be performed based on the condition

@Nihantra-Patel Nihantra-Patel requested a review from a team as a code owner April 25, 2024 09:49
@Nihantra-Patel Nihantra-Patel requested review from ankush and removed request for a team April 25, 2024 09:49
@ankush ankush self-assigned this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Want to add multiple buttons per line in list view support 希望列表视图可以每行增加多个按钮
2 participants