Extending functionality of List View onload

Hi,
I was trying to add functionality to onload event of a document List view.
How ever the below method updates the onload method, but it overwrite the original code in onload method

frappe.listview_settings['Lab Test'].onload = function (cur_list) {  
// your code
}

I came up with the following approach to add more script to the onload method without removing the original code

let old_onload = frappe.listview_settings['Lab Test'].onload;
var new_onload = function (cur_list) {  
    old_onload(cur_list);
    cur_list.filter_area.filter_list.add_filter('Lab Test', 'patient', 'Equals', 'Maram Alsubaie')
    cur_list.refresh()
}
frappe.listview_settings['Lab Test'].onload = new_onload

Please share your views and share if there is any better approach.

Regards

4 Likes