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

367
Views
Filtering Array for table using React JavaScript

I've created a date filter for my table that if date exist it shows that data only else it shows all data . It shows all data only even though i entered date it didn't work. I really need this community help for this. i feel exhausted working on this. please guide me ill give my sandbox link : https://codesandbox.io/s/musing-mendel-w4n6g

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hi (Vanakkam) Karthikeyan,

Thank you for sharing the codesandbox link.

The 'componentDidMount' lifecycle method does not get called each time the rsuite daterangepicker triggers onChange, based on my observation. ReactJS documentation here provides more details of when the method is triggered, when it is appropriate to use it, etc.

If it is acceptable to filter the data within the 'async' handleChange method, the filtering works.

Here is one possible implementation:

  async handleChange(dates) {
    const dtfmt = "yyyy-MM-DDTHH:mm:ss";
    const data = await (await fetch("/data.json")).json();
    dates && dates.length > 0 ?
      (data || []).length &&
      this.setState({
        startDate: dates[0], // redundant
        endDate: dates[1], // redundant
        datefilter: data.filter(
          d => moment(d.Date, dtfmt).isBetween(
            moment(dates[0], dtfmt), moment(dates[1], dtfmt)
          )
        )
      }) :
      (data || []).length &&
      this.setState({
        startDate: '',
        endDate: '',
        datefilter: data
      });
  };

Edited the solution above to handle 'empty' dates.

And, this is how it filtered the dates:

Screenshot of codesandbox

If it is mandatory to place the data-load in lifecycle methods, you may want to declare a separate 'async' method & then call that from the relevant lifecycle method/s (may be like componentDidUpdate ?).

about 4 years ago · Juan Pablo Isaza Report
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!