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

184
Visualizações
Rows not defined when it is defined inside if-else block for table data filter

I am doing filtration on my data on multiple conditions using if-else. The if is for when a person clicks advance search and then we have to filter based on certain fields and the else is based on the regular search field and if that is empty, the whole table data is shown. The logic should be alright but when compiling, React throws me an error

'rows' is not defined no-undef

Is it because it is inside the if-else and should be declared outside? I tried declaring a null rows const but if I do that, it never goes into the if-else and shows me 0 records. What should I change for this to work?

relevant code:


  if (advanceSearch == true) {
    const rows = data.filter((item) => {
      return (
        item.doc_id.toString().match(new RegExp(searchDocID, "gi")) ||
        item.invoice_id.toString().match(new RegExp(searchInvoiceID, "gi")) ||
        item.cust_number.toString().match(new RegExp(searchCustNum, "gi")) ||
        item.buisness_year.toString().match(new RegExp(searchBizzYear, "gi"))
      )
    });
  } else {
    const rows = searchInput
      ? data.filter((item) => item.cust_number.toString().match(new RegExp("^" + searchInput, "gi")))
      : data;
  }
  

    return (
      <div style={{ width: '100%' }}>
        <DataGrid
            rows={rows}
            columns={columns}
about 4 years ago · Juan Pablo Isaza
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