Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
Set State to Array Filter value on condition

So i want to use array.filter to values that are not empty string in an object in the following senario

setData(
                _.filter(rows, item => {
                    return (
                        item.firstName.toLowerCase().includes(filterTable.searchByName.toLowerCase()) &&
                        item.email.toLowerCase().includes(filterTable.searchByEmail.toLowerCase()) &&
                        item.cognitoId.toLowerCase().includes(filterTable.searchByCognitoId.toLowerCase()) &&
                        item.mfaEnabled.toString() === filterTable.searchByMfa.toString()
                    );
                })
            );

i can use ifelse to what values are there but that will be a hell of a long ifelse

in the above code i want to add those items in _.filter that's value is !== ''

for example if filterTable.email === '' then i want following

setData(
                _.filter(rows, item => {
                    return (
                        item.firstName.toLowerCase().includes(filterTable.searchByName.toLowerCase()) && 
                        item.cognitoId.toLowerCase().includes(filterTable.searchByCognitoId.toLowerCase()) &&
                        item.mfaEnabled.toString() === filterTable.searchByMfa.toString()
                    );
                })
            );
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Add another && for the search property

Try like this

setData(
    _.filter(rows, item => {
        return (
            filterTable?.searchByName &&
            item.firstName
                .toLowerCase()
                .includes(filterTable.searchByName.toLowerCase()) &&
            filterTable?.searchByEmail &&
            item.email
                .toLowerCase()
                .includes(filterTable.searchByEmail.toLowerCase()) &&
            filterTable?.searchByCognitoId &&
            item.cognitoId
                .toLowerCase()
                .includes(filterTable.searchByCognitoId.toLowerCase()) &&
            item.mfaEnabled.toString() === filterTable.searchByMfa.toString()
        );
    })
);
about 4 years ago · Juan Pablo Isaza Relatório

0

This fixed it thanks Amila for helping

setData(
            _.filter(rows, item => {
                return (
                    (filterTable?.searchByName !== ''
                        ? item.firstName.toLowerCase().includes(filterTable.searchByName.toLowerCase()) ||
                          item.lastName.toLowerCase().includes(filterTable.searchByName.toLowerCase())
                        : true) &&
                    (filterTable?.searchByEmail !== ''
                        ? item.email.toLowerCase().includes(filterTable.searchByEmail.toLowerCase())
                        : true) &&
                    (filterTable?.searchByCognitoId !== ''
                        ? item.cognitoId.toLowerCase().includes(filterTable.searchByCognitoId.toLowerCase())
                        : true)
                );
            })
        );
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda