Skip to content

Instantly share code, notes, and snippets.

@Octagon-simon
Created June 4, 2022 13:11
Show Gist options
  • Select an option

  • Save Octagon-simon/198433f360129845556516febb59c677 to your computer and use it in GitHub Desktop.

Select an option

Save Octagon-simon/198433f360129845556516febb59c677 to your computer and use it in GitHub Desktop.
//attach event listener
document.querySelector('#inp_search').addEventListener('input', function(){
//store the search query
let value = this.value.trim();
//check if value is not empty
if(value){
//store matching record IDs
let matchingIDs = [];
//loop index
let ind = 1;
//loop through the data to find matching text
while(ind < Object.keys(tableData).length){
//check if current property contains the search query
if(tableData[ind][0].includes(value) ||
tableData[ind][1].includes(value) ||
tableData[ind][2].includes(value) ||
tableData[ind][3].includes(value)){
//store the id of the record
matchingIDs.push(ind);
}
//increment index
ind++;
}
//invoke the function by passing in the matching IDs
buildTable(matchingIDs);
}else{
//invoke the build table function without providing an argument
buildTable();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment