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

371
Visualizações
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 Respostas
Responde à pergunta

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 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