[V7] How to hide/show grid in child table, based on parent field value?

Hi all,

i’ve a problem using Depends On on child table based on a field value in parent doc.

Basically i would like to hide a field in the child table if Price List is not a Buying one.

So, I set in child doc, Depends On field like following pic:

What’ i expect is to have suggested_selling_rate hidden when Price list is not a buying one, but seems its not working, see pic.

What i’m doing wrong? If confirmed, i’ll open an issue

Thx

I don’t think grids support depends on.

@rmehta …thx for the answer …any hint on how to hide grid?

Hi @JoEz JoEz,
Did you get the answer of this question?

Actually, I am also looking for the same.

Regards
Ruchin Sharma

nope …

@JoEz and @ruchin78

Try grid.toggle_enable.
Refer this -

Or
grid.set_column_disp

4 Likes

@ruchin78 and @JoEz

Form’s display depends on does not support child tables. However I achieved it using

var df = frappe.meta.get_docfield("Chid DocType", fieldname , cur_frm.doc.name);
df.hidden = 1; 
3 Likes

@Nick
While using the same, it giving me an error saying, df is not defined.

BTW: Here is the solution of the problem, I was looking for. I actually was looking to set the list_view property using script and by using the below script, you can change any property of any field:

var d1 =  {   
              "field_name": "video"
 	  }

frappe.call({
		args: d1,
    		method: "library.update_items.set_property",
    		callback: function(r)
		{ }
@frappe.whitelist()
def set_property(field_name):
	make_property_setter('Shipping List', field_name, "in_list_view", 0, "Check")

In the above example ’
Shipping List: Is a DocType
field_name: is the name of the field
in_list_view: is the property that I want to set, you can pass any property like shown below:
idx’: ‘Int’,
‘label’: ‘Data’,
‘fieldtype’: ‘Select’,
‘options’: ‘Text’,
‘permlevel’: ‘Int’,
‘width’: ‘Data’,
‘print_width’: ‘Data’,
‘reqd’: ‘Check’,
‘unique’: ‘Check’,
‘ignore_user_permissions’: ‘Check’,
‘in_list_view’: ‘Check’,
‘in_standard_filter’: ‘Check’,
‘in_global_search’: ‘Check’,
‘bold’: ‘Check’,
‘hidden’: ‘Check’,
‘collapsible’: ‘Check’,
‘collapsible_depends_on’: ‘Data’,
‘print_hide’: ‘Check’,
‘print_hide_if_no_value’: ‘Check’,
‘report_hide’: ‘Check’,
‘allow_on_submit’: ‘Check’,
‘depends_on’: ‘Data’,
‘description’: ‘Text’,
‘default’: ‘Text’,
‘precision’: ‘Select’,
‘read_only’: ‘Check’,
‘length’: ‘Int’,
‘columns’: ‘Int’,
‘remember_last_selected_value’: ‘Check’,
‘allow_bulk_edit’: ‘Check’,

0: is the value of the property means I am making in_list_view=no
check: is the type of the property like in_list_view is a check type property

To use the function make_property_setter you need to import the library using:

from frappe.custom.doctype.property_setter.property_setter import make_property_setter

in your python code.

For further details see customize_form.py

Regards
Ruchin Sharma

1 Like

@ruchin78
Its strange that you are getting an error, but it works smoothly in custom script at erpnext.com as far as hiding a field is concerned. I am also currently using it in the production env of client.

Thx, i’ll have a look at that.

In Customize Form you can create a new Section Break before the table, then make the section Display Depends On whatever you want.

@Nick
Hi,
Now, it is working fine but the only issue I am facing is, I am applying on the fields which are list_view enabled and I don’t want them to display when in the grid after getting hide, but it is still being displayed.
I tried refreshing the fields and the form too, but didn’t work, any idea?

Regards
Ruchin Sharma

@Sangram
It is working but actually, it doesn’t hide the column from the gird.

Regards
Ruchin Sharma

@ruchin78 did you get it solve this?

Hello @Thiago_Henry. I think eval:parent.field == value in depends on should work on child tables. I’ve tried using it on a custom doctype and it works like a charm. :slight_smile:

ok Thanks @littlehera.

please give an example.

thank you

Regarding to make_propertry_setter: this is working but the problem that it will change the property of the field in the document which will effect on all the documents of that document type.

eval:parent.field == value is working fine but it is only used for displaying and hiding the field if the “in list view” property is not enabled (in other words, if “in list view” property is enabled, the field will be displayed even if the eval:parent.field == value result was FALSE).

grid.set_column_disp is making the field visible if it is hidden so it is useful for displaying the field, but it is not related to “in list view”.

grid.toggle_enable: this did not work with me really :slight_smile:

But after all, if we are talking about displaying and hiding the field of the child table (depending on some condition), then all of this is useless because it is not logic to change the document type structure as this will effect on any new document will be created.

I would if there is a solution that is effecting on the document without effecting on the doctype.

Regards
Bilal

hello
What if i want a parent field to appear when a childtable field(checkbox) is checked
Which depends on script do i use

Hello,
I have tried to implement similar feature where the visiblity of fileds in the child table show/hide depending on the status of a select field in the parent doctype.

Adding the code → eval:parent.status == “Requested” in the the “display depends on” for the child table field works and it hides the field on the child table detail view. the problem i am facing is if that field is on the list view it won’t hide it.

I even tried to show/hide child tables using jquiery tags. to some extent it works but still buggy when i interact with child table. like chaning column settings from the front end.

On our erp implementations changing the visiblity and width of child tables is a huge headache for users. I want to have a more streamlined approach to change the layout of the child table based on parent field status.