Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda