Add Button in Child Table

I want to add button in child table like upload and download.

2 Likes

let btn = document.createElement(“button”)
btn.innerText = “abc”
frm.fields_dict.items.grid.wrapper.find(“.grid-upload”).removeClass(“hide”).parent().append(btn)

items is child table name
you can delete removeClass(“hide”) if download & upload btn alread existed.

Hii @magic-overflow

I want to add button not want to hide it.

I don’t think my code hide anything.

Ok, my code might not understandable. Hope other has a better one.

frappe.ui.form.on("Sales Invoice", {
	onload: function (frm, cdt, cdn) {
	let btn = document.createElement('a');
	btn.innerText = 'Refresh';
	btn.className = 'grid-upload btn btn-xs btn-default';
	frm.fields_dict.items.grid.wrapper.find('.grid-upload').removeClass('hide').parent().append(btn);
	btn.addEventListener("click", function(){
	});
	}	
})

Thanks for hint @magic-overflow :grinning:. This is what I’m looking for.

5 Likes

There (now at least) is a more elegant solution:

frm.fields_dict["my_table"].grid.add_custom_button(__('My Label'), function() {});

2 Likes

Which event is suitable for this? I use refresh event and sometimes my buttons doubled, tripelled :slight_smile:

You can also apply styling to your custom button How to add a custom button on child table - #4 by sanjay

1 Like

I use the refresh event and haven’t had that problem, so far.
What Frappe Version are you on?
Have you tried onload instead?