Actionlistener for List View

I’m looking for a way to execute a custom script in the list view of a doctype.

I know the frappe.ui.form.on() method but this won’t help me in this issue as long as I don’t know weather there is a listener for the list view. Simply JS code placed in a doctype_list.js only executes single time on reload the page but not every time on “refresh” the view.

you can add action listener on refresh event of list.

Ref:
https://github.com/frappe/frappe/blob/develop/frappe/core/doctype/file/file_list.js#L145

3 Likes

Nice to know =) thank you very much

Is there a chance to get also the data of the list in one of these events?

I tried

  • refresh
  • list_view_doc
  • post_render

but when the function is invocated the data-parameter is undefined. I try to set the status row of my list to a certain value, that depends on values of other objects. I also tried the get_indicator for this issue but this does not allow any asynchronous calls. Here is a snippet:

frappe.listview_settings['Concert'] = {
    add_fields: ["sales_order","quotation"],
    get_indicator: function(doc) { 
        return [__("Pending"), "grey pending-status", ""]
    },
    any_event:function(data) {
            
            // for each data.element:
            if(d.sales_order!=="") {   
                setStatus(d,'green','Sales Order');
            }
            // ansonsten kann ein Angebot vorhanden sein
            else if(d.quotation!=="") {
                frappe.call({
                    "method": "frappe.client.get",
                    args: {
                            doctype: "Quotation",
                            name: d.quotation
                    },
                    callback: function (data) {
                        if(data.message.status=="Lost" || new Date(d.concert_beginning) < new Date()) {
                            var color = "red";
                            var state = "Lost Quotation"
                        }
                        else {
                            var color = "yellow";
                            var state = "Quotation"
                        }
                        var e = findRowByQuotation(data.message.name);
                        setStatus(e!==false?e:"Any Error",color,state);
                    }
                });
            }
            // nothing
            else {
                if(d.concert_beginning!=="" && new Date(d.concert_beginning) < new Date()) {
                    setStatus(d,'red','Expired');
                }
                else {
                    setStatus(d,'grey','Request');
                }
            }
   
    } 
};

Found the solution in doing a setTimeout( ,100) so the data parameter is not empty anymore

@Alexander_Haase Did you find a way out to render data when list view is changed or refreshed?