function applyFilter(userInput){
/*
Use css to set the display to none first
*/
let allClientIDRows = document.querySelectorAll("ClientID-row > a");
for(let i = 0; i < allClientIDRows.length; i++){
let row = allClientIDRows[i]
let ClientID = row.getElementsByClassName("ClientID")[0]
if(allClientIDRows[i].textContent.trim() == userInput.trim()){
//You can also convert to lowercase for more accurate result
allClientIDRows[i].style.display = "inline";
}
}
}
This is the function that applys the filter to allow you to search and show what you search for and not the entire form.
i am only looking to show the searched item and not the entire spreadsheet
Data
Type in your ID
No ID FOUND
Loading
Failed to get data. Please refresh
function setErrorDisplay(loaderElm, allClientIDsElm, errorMessageElm){
loaderElm.style.display = "none"
allClientIDsElm.style.display = "none"
errorMessageElm.style.display = "block"
}
let allClientIDsElm = document.getElementById("allClientIDs")
let loaderElm = document.getElementById("loader")
let errorMessageElm = document.getElementById("errorMessage")
fetch("
{
https://api.apispreadsheets.com/data/").then(res=>{
/>
if (res.status === 200){
//sucess
res.json().then(data=>{
const yourData = data["data"]
for(let i = 0; i < yourData.length; i++){
let rowInfo = yourData[i]
let rowInfoDiv = document.createElement("div")
rowInfoDiv.classList.add("ClientID-row")
let rowClientID = document.createElement("h4")
let rowClientIDNode = document.createTextNode(rowInfo["ClientID"])
rowClientID.appendChild(rowClientIDNode)
rowClientID.classList.add("ClientID")
let rowRA = document.createElement("p")
let rowRANode = document.createTextNode(rowInfo["RA"])
rowRA.appendChild(rowRANode)
rowRA.classList.add("RA")
rowInfoDiv.appendChild(rowClientID)
rowInfoDiv.appendChild(rowRA)
allClientIDsElm.appendChild(rowInfoDiv)
}
loaderElm.style.display = "none"
allClientIDsElm.style.display = "block"
errorMessageElm.style.display = "none"
}).catch(err => {
setErrorDisplay(loaderElm, allClientIDsElm, errorMessageElm)
})
}
else{
setErrorDisplay(loaderElm, allClientIDsElm, errorMessageElm)
}
}).catch(err =>{
setErrorDisplay(loaderElm, allClientIDsElm, errorMessageElm)
})
This is the HTML part that runs the html search part
For some reason when i run with the function its still showing all the spreadsheet. What i am trying to do is How to make a search list in which element is only shown when user search for its exact value
when you type it shows you the result but the form will be empty untiil you type
i tryed with a search function with a filter but it shows the entire spreadsheet. Maybe i am doing something wrong or messed up somewhere in the code.
the applyfilter isnt working for me maybe there is another way i can do this
Search Through exel file using a search html
Programing Coderfunda
February 06, 2024
No comments
Related Posts:
HTML Comment tag with Example In HTML Comment tags are used to insert comments in the HTML code. HTML code written between comment tag can’t be execute. Syntax: <!-- Write… Read More
Write HTML Using Notepad or TextEdit Web pages can be created and modified by using professional HTML editors. However, for learning HTML we recommend a simple text editor like Notepad… Read More
HTML Introduction What is HTML? HTML is the standard markup language for creating Web pages. HTML stands for Hyper Text Markup Language HTML describes the structure… Read More
HTML Elements HTML Elements An HTML element usually consists of a start tag and end tag, with the content inserted in between: <tagname&g… Read More
HTML Basic Examples Don't worry if these examples use tags you have not learned. You will learn about them in the next chapters. HTML Documents All HTML documents m… Read More
0 comments:
Post a Comment
Thanks