Custom Script to highlight rows of child table

Hi ERPNEXT Community,

I have been scouring the whole forum and on google to no avail for a particular problem I wanna solve.

I want to highlight certain rows in my Sales Order Item table when the rate is 0, but I can’t seem to find anything that could help me do that.

There are two previous topics that discuss that but none seems to work for me.

Any ideas on how to do this?

frappe.ui.form.on('Sales Invoice', {
    setup: function (frm) {
        frm.set_indicator_formatter('item_code',
            function (doc) {
                return (doc.docstatus == 1 || doc.qty <= doc.actual_qty) ? "green" : "orange"
            })
    }
});

The above is used to format lines based on stock availability. Green if there’s enough stock, orange otherwise. See if you can modify it to highlight where rate is zero

Thank you for your help.

Is this code used to add an indicator light next to the item? or will it highlight the whole row?

Just the item. Sorry, missed the row bit.

I’ve figured this out and thought I would share my code in case anyone wanna do the same:

frappe.ui.form.on('Sales Order', {
	    onload: function(frm, cdt, cdn) {
		    cur_frm.fields_dict["items"].$wrapper.find('.grid-body .rows').find(".grid-row").each(function(i, item) {
	            let d = locals[cur_frm.fields_dict["items"].grid.doctype][$(item).attr('data-name')];
	            if(d["rate"] == 0){
		            $(item).find('.grid-static-col').css({'background-color': 'yellow'});
	            }
        });
	    }
});

I format my child row based on the Sales Order Item field: “Rate”.

12 Likes

Will the color show on print format?