Filter on List view onload

I am working on the library management app, and in library transaction i have created library_transaction_list.js and i that i am running this code
/ var data; // Declare data as a global variable

// frappe.listview_settings[‘Library Transaction’] = {
// onload(listview) {
// frappe.call({
// method: ‘library_management.library_management.doctype.library_transaction.library_transaction.get_session_data’,
// callback: function(response) {
// var member_id = response.message;
// data = member_id;
// frappe.msgprint(Member ID: ${member_id});
// frappe.msgprint(Member ID: ${data});
// },
// filters: [
// [‘library_member’, ‘=’, data]
// ]
// });
// }
// };

in this i am able to fetch the values of member_id and data, but when iam appyling filter, then its not working. i have used similar filter condition on get indicator method, it’s working fine. but on filter it’s not working. help me out on this

Hi @abhay19,

I think the syntax is not proper so please check it.

frappe.listview_settings['Library Transaction'] = {
  onload: function(listview) {
    frappe.call({
      method: 'library_management.library_management.doctype.library_transaction.library_transaction.get_session_data',
      callback: function(response) {
        var member_id = response.message;
        var data = member_id;
        frappe.msgprint('Member ID: ' + member_id);
        frappe.msgprint('Member ID: ' + data);

        // Apply filter inside the callback
        listview.filter_area.add_filter('library_member', '=', data);
        listview.refresh();
      }
    });
  }
};

Please set your fieldname, doctype, and code according.

Thank You!

Hi @NCP Can we add custom button in List view and while clicking i have to show the tasks based on last updated on in desc order . is this possible?
this is a client request.

I think it’s tricky, and I’m not sure if it’s possible or not.

So I have tried like this

listview.filter_area.add_filter(‘DocType Name’, ‘variable_name’, ‘=’, assigning_variable_name);

listview.filter_area.add_filter is not a function

Check the other reference: List View filter - #2 by NCP

1 Like