Hide row from child table

Hi everyone, I need to Hide a row in earnings (child table) when 2 conditions are true.

When doc is validated and when the name of the component in the child table is ‘AFP1 EMPLEADOR’.

I need to hide for printing or hide it from the DocType (I don’t need to delete it, just hide, because I need it for calculations)

this what I have so far. but I need the method to hide that specific row, and I dont know if “onload” is the specific trigger for it.

frappe.ui.form.on("Salary Slip", {
	onload: function(frm) {
		var tbl = cur_frm.doc.earnings || [];
		var i = tbl.length;
		var estado = cur_frm.doc.status
		while (i--)
		{
			if (estado == 'Paid')
			{
				if(tbl[i].salary_component == 'AFP1 EMPLEADOR')
				{
					cur_frm.doc.earnings[i].hide(); //THIS IS WRONG OBVIOUSLY
				}	
			}
		}
	}
})

Any suggestions?

@josmediaz21

Instead of hiding it on doctype hide it in your custom print format.

Then you can ignore that rows in your calculation. Write the script for your calculation.

1 Like

Try using toggle display. Below is an example:
cur_frm.toggle_display("fieldname", false/true) to hide / unhide field

1 Like

I hide it from the print format.

I need to hide some child table rows on doctype as per login user. Any solution?

You can hide child table rows by user role. Try this in the js

if (frappe.user.has_role(‘Support Team’)) {
frappe.meta.get_docfield(“Name of the Child Table”,“field_name”, cur_frm.doc.name).hidden = 1;
}

It is not working for particular row, it hides the whole column.

I got it, by using the jquery . Its working fine now. :grinning:

frappe.db.get_value(“User”,frappe.session.user,“company”, function(v){
var data = frm.doc.accounts;
data.forEach(function(e){
if (e.company != v.company){
$(“[data-idx='”+e.idx+“']”).hide()
}
})
});

3 Likes

refresh : function(frm){
var table=frappe.meta.get_docfield(“User”, “email”,frm.doc.name);
table.hidden=1;
frm.refresh_fields();
}

Greetings,

Following on from this thread, how would I go about hiding a particular row when printing if the value of a field is equal to zero?

For example, in the Sales Order item table, if I have the field Rate set to 0.00 how could I hide the entire row for that item when it comes to printing?

Many thanks in advance.

The solution is fine if you only got 1 child table, because the selctor “data-idx=‘any number’” will match with any child table on your Form View. To restrict hiding to a single certain child table use this:

let datatable = $("[data-fieldname='veranstaltung_gaesteliste']");
for (let row of frm.doc.veranstaltung_gaesteliste) {
	if (row.some_field == 'some_value') {
		let child = $(datatable).find(`[data-idx='${row.idx}']`);
		child.hide();
	}
}

Where ‘veranstaltung_gaesteliste’ is the Field Name of the Table Field.

unfortunately this effects all the child tables

@josmediaz21 hi i have the same exact problem as yours please help me
how did you manage to hide it in the print format