Derived field filtering


#1

Hey community, i hope you can help me with a filtering problem, the situation is: I have a derived field used from other source like this:

const companyCodeByName = {
    name: 'company_code',
    label: 'company_code',
    type: 'ATTRIBUTE',
    dependencies: ['company_name'],
    reverse: (item) => {
        const filters = cf.getIManager().get('api').getFilters();
        const nameFilter = filters.find((f) => f.getLabel() === 'Company Name');
        const companyName = nameFilter && nameFilter .getValue()[0];
        return getCompanyCodeByName(companyName, item);
    },
    function: (item) => {
        let name = item.companyNames[0];

        return name;
    },
};

And in my main source i have this field definition in the metadata:

"MainSource": {
        fields: {
            company_name:  {
                label: 'Company Name',
                type: 'ATTRIBUTE',
            },
            company_code: {
                label: 'Company Code',
                type: 'ATTRIBUTE',
            },
        },
    },

When I try to apply a filter selecting the company code from my derived field the widgets with my main source are not filtered.
I did something wrong?


Labels handling for derived fields
#2

Hi @dani i don’t know what exactly you want to do here but the first thing that i can see is your labels definition, the company code label for the derived field is different than the main source company code field. Remember this: if you wan to apply filters across the different sources you need to have the same labels for the common fields like the company_code field, I hope I’ve helped, let me know if that is the solution or maybe you could be more specific with your issue.


#3

Well, yeah that was the solution, it works for me you have the reason after take a look at the documentation i noticed that the labels need to be the same to filter across multiple sources with common fields, thanks for the help, appreciate it, :slight_smile: