How to add a custom button on child table

Hello all

I’m trying to add a client-side custom script which will display a custom button on the Quotation Items child table:

frappe.ui.form.on('Quotation Item', 'refresh', function(frm) {
    frm.add_custom_button(__("Do Something"), function() {
        alert("button");
    });
});

1 However this code never executes! Why not?

2 is it possible to add a button on the child table, not on the parent (Quotation), eg next to Download

Screenshot%20at%202021-01-20%2010-53-14

Thanks so much

2 Likes

frappe.ui.form.on(‘Quotation’, ‘refresh’, function(frm) {
frm.doc[“items”].grid.add_custom_button(__(“Do Something”), function() {
alert(“button”);
});
});

1 Like

Ah… @sanjay, I was so close to marking this as the solution (and giving you a like), but then I thought “let me first test it”.

I’m afraid the “Do Something” button does not show, but worse, I also loose the “Get items from” button on the top of the Quotation and the “Add Multiple” button on the Quote Items grid. :slight_smile:

My apologies, below is working code:

frappe.ui.form.on('Quotation', {
	refresh(frm) {
		frm.fields_dict["items"].grid.add_custom_button(__('Hello'), 
			function() {
				frappe.msgprint(__("Hello"));
        });
        frm.fields_dict["items"].grid.grid_buttons.find('.btn-custom').removeClass('btn-default').addClass('btn-primary');

	}
})

image

9 Likes

You’ve earned it!
Thanks so much

1 Like