How to Filter child table

Hi all,
I have a field (client) with a child table cc_bar_restaurante (fields numero_registo, descricao, status_conta_corrente)
trying to filter (set_query and get_query) the content of the child table for records with PAGO or NÃO PAGO only but does not filter !!! What am I missing?
My table has no link fields …the records are added via a script.

This is the code on onload
frm.fields_dict.cc_bar_restaurante.grid.get_field(‘numero_registo’).set_query = function() {
return {
filters: {
“status_conta_corrente”:“Pago”

			}
		}

	}		

HI,
Go through these links ,it will be helpful.

Do something like this:

9 Likes

@KanchanChauhan thanks for the tips but what I need is to filter records already inserted on the table … that filter is when I need to add new record so it filters the records by the filters set, correct?
The idea is when you load the record named “John Dude” on the Child will show all records already inserted (status pay and not paid) but I need to see only the NOT PAID records.
So this should be a filter or query when records are retrieved or to be and set on the Grid.

tried like cur_frm.grids.filter = [‘status_conta_corrente’,’=’,‘Pago’]

did not work :frowning:

Anyone with a solution!!! or tables should always have a link field???
my case I have not links on this table and records are added via Refresh when the “Nome Cliente” is selected on the grid.

get_query or set_query is used to filter the results of a link field while entering values manually. As you are populating the rows via a script, you should add those rows based on filters beforehand. Once the rows are added, it cannot be filtered out from js.

But can’t I filter a doctype already populated before showing the result?
Example in other languages when calling the table of the Db you can call
like a queries using SQL “select name,status from xxx where status=‘free’”
and this can be your connection so the result is shown… What about here
when calling or assigning the doctype the grid?
I tried to see how can a filter be added on grid init or Setup but no
knowledge yet on how to?

What can be done is cases like this with no link fields? Or the best is
always to have at least one link field?

Thanks.

In Quality Inspection DocType, using a script, I’m adding the list of checks that has to be performed into a child table(Quality Inspection Reading) based on item_group.

But now, the options for each check is different. i.e., the options for a particular check should be filtered based on the check(Options are coming from another table - Quality Check Options where all the options are stored).

I’ve to use get_query to achieve the above functionality.

Struggled a lot to achieve this. Even refresh_field is not working. And finally found your(@nabinhait ) reply.

As you said, if get_query and set_query are for only manual entires, how can I add them beforehand?

Tutorial or detailed note is really appreciated.

On any specific condition how it will work?
In my child doctype there is check box, if it checked then related row should display on screen

1 Like

Hello @Vajra, you may try something like this:

frappe.ui.form.on("Delivery Note", "refresh", function(frm) {
    frm.fields_dict['items'].grid.get_field('CHILD_FIELD_NAME_TO_BE_FILTERED').get_query = function(doc, cdt, cdn) {
        var child = locals[cdt][cdn];
        //console.log(child);
        return {    
            filters:[
                ['IS_IT_OK_FIELD', '=', child.CHECKBOX_FIELD]
            ]
        }
    }
});

In my example child field is Batch. So “IS_IT_OK_FIELD” is a field on my Batch doctype. “child.CHECKBOX_FIELD” is a field on a delivery note item grid.

2 Likes

Thank for the help.It is now working.

@vajra can you help me with the code

Regards
Sheetal Pawar

Thanks, It works for me

1 Like

if Leave Type == “Earned Leaved” then in clubbed Leave Type should I show only Sick Leave and paternity Leave ?