How to change listview property of child table

Hi All,
I need to change in_list_view property of child table based on field change in parent doctype

How can i do that?

Here’s a simple solution:


  frappe.ui.form.on("Your Parent DocType", {
      refresh(frm) {
          frm.trigger('update_child_columns');
      },

      your_field(frm) {  // Parent field that triggers the change
          frm.trigger('update_child_columns');
      },

      update_child_columns(frm) {
          if (!frm.fields_dict.your_child_table) return;

          let grid = frm.fields_dict.your_child_table.grid;

          if (frm.doc.your_field === "some_value") {
              // Show the column
              grid.fields_map['column_name'].in_list_view = 1;
          } else {
              // Hide the column
              grid.fields_map['column_name'].in_list_view = 0;
          }

          // Refresh the grid
          grid.visible_columns = null;
          grid.refresh();
      }
  });
2 Likes