Triggering an action when a child table row is selected

I am trying to trigger some events when a row in a child table is selected. However, it triggers when the row is opened as a form in a table field

frappe.ui.form.on('Despatch Plan', {
    sales_orders_on_form_rendered: function(doc, cdt, cdn) {    
        frappe.msgprint("On click of sales order item row");   
    }
});

When we select a row in the child table, I would like an event to be triggered

Hi @Dharanipathi,

Please apply the client script for it.
We did apply on Sales Order DocType. so please check the syntax.

frappe.ui.form.on('Sales Order', {
    refresh: function(frm) {
        frm.fields_dict.items.grid.wrapper.on('click', '.grid-row', function(event) {
            // Trigger your desired event here
            frappe.msgprint("Clicked the Sales Order Row.");
        });
    }
});

Please set your doctype, fieldname, and child table field name.
I think your problem will solve.

Thank You!

5 Likes

Thank you, It’s working :upside_down_face:

It’s working, but I want to delete the chosen row and then save the form.
Can you help?

Please check it.

frappe.ui.form.on('Sales Order', {
    onload: function(frm) {
        frm.fields_dict.items.grid.wrapper.on('change', '.grid-row-check', function(event) {
            var grid = frm.fields_dict.items.grid.grid_rows;
            
            grid.forEach(function(row) {
                if (row && row.wrapper.find('.grid-row-check').is(':checked')) {
                    var docname = row.doc.name;
                    var grid_row = frm.get_field("items").grid.grid_rows_by_docname[docname];
                    if (grid_row) {
                        grid_row.remove();
                    }
                }
            });
            frm.save();
            
        });
    }
});

Thank you, It’s working.