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

144
Views
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 answers
Answer question

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