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

153
Visualizações
Generate new table when searching

I am trying to generate a table from an array with a searching feature. With every letter typed in the search bar the items that contain that specific string will be displayed.

I have come to the conclusion to generate the whole table with every keystroke rather than editing the current.

This is where I am at:

What´s currently typed in the searchbar:

  let searchBar = document.getElementById('search-input');

    let value = " ";
    searchBar.addEventListener(`keyup`, function(){
        value = this.value

How I make the table:

let tableUsers = document.getElementById("tabell");

function drawTable() {
    let table = document.createElement("table");
    let tableHead = document.createElement("thead");
    let colHeads = ["Name"];

    for (let header of colHeads) {
        let cell = document.createElement("th")
        cell.innerHTML = header;
        tableHead.appendChild(cell);
    }
    table.appendChild(tableHead)

    for (let x of people) {

        let row = document.createElement("tr");

        let name = document.createElement("td");
        name.innerHTML = x.name.first + "&nbsp" + x.name.last;
        row.appendChild(name);

        table.appendChild(row);
    }

    tableUsers.appendChild(table);
}
drawTable()

I am trying this:

let str = x.name.first.toLowerCase()

        if (str.includes(value)){
        //code
        }

Is it possible to do it this way? Or possible at all using JS and large arrays without using a lot of pc resources? Any help is greatly appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Inside if statement, you need to create new array then push the values inside it then you can pass a new people as a parameter to drawTable function and call it like drawTable(people)

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