Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!