I’m using Google Apps Script and JavaScript to search through the data on a spreadsheet.
Rows 0 and 2 – 5 all have a combination of numbers and letters and return results without issue. Row 1 has only numbers, and returns no search results at all from any rows when uncommented.
I also tried to change this to number, row 1 still returns no results
<div>
<label for="search-box" class="form-label">Search</label>
<input type="text" class="form-control" id="search-box" placeholder="Input Status or Recent
User here." onchange="search()">
</div>
<div class="container">
<table class="table">
<thead>
<tr>
<th scope="col">Asset Number</th>
<th scope="col">Recent User</th>
<th scope="col">Last Sync</th>
<th scope="col">Status</th>
<th scope="col">OS Version</th>
</tr>
</thead>
<tbody id="table-body">
</tbody>
</table>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script>
function search() {
google.script.run.withSuccessHandler(function(data) {
let searchText = document.getElementById("search-box")
let tableBody = document.getElementById("table-body")
tableBody.innerHTML = ""
let filterData = data.filter(row => row[0].toUpperCase().match(searchText.value.toUpperCase()) ||
row[1].toUpperCase().match(searchText.value.toUpperCase()) ||
row[2].toUpperCase().match(searchText.value.toUpperCase()) ||
row[3].toUpperCase().match(searchText.value.toUpperCase()) ||
row[4].toUpperCase().match(searchText.value.toUpperCase()) ||
row[5].toUpperCase().match(searchText.value.toUpperCase()))
filterData.forEach(row => {
let tableRow = document.createElement("tr")
let ouData = document.createElement("td")
ouData.textContent = row[0]
tableRow.appendChild(ouData)
let aNumberData = document.createElement("td")
aNumberData.textContent = row[1]
tableRow.appendChild(aNumberData)
let rUserData = document.createElement("td")
rUserData.textContent = row[2]
tableRow.appendChild(rUserData)
let lSyncData = document.createElement("td")
lSyncData.textContent = row[3]
tableRow.appendChild(lSyncData)
let rActivityData = document.createElement("td")
rActivityData.textContent = row[4]
tableRow.appendChild(rActivityData)
let sData = document.createElement("td")
sData.textContent = row[5]
tableRow.appendChild(sData)
tableBody.appendChild(tableRow)
})
}).returnTable()
}
google.script.run.withSuccessHandler(function(data) {
let tableBody = document.getElementById("table-body")
data.forEach(row => {
let tableRow = document.createElement("tr")
let ouData = document.createElement("td")
ouData.textContent = row[0]
tableRow.appendChild(ouData)
let aNumberData = document.createElement("td")
aNumberData.textContent = row[1]
tableRow.appendChild(aNumberData)
let rUserData = document.createElement("td")
rUserData.textContent = row[2]
tableRow.appendChild(rUserData)
let lSyncData = document.createElement("td")
lSyncData.textContent = row[3]
tableRow.appendChild(lSyncData)
let rActivityData = document.createElement("td")
rActivityData.textContent = row[4]
tableRow.appendChild(rActivityData)
let sData = document.createElement("td")
sData.textContent = row[5]
tableRow.appendChild(sData)
tableBody.appendChild(tableRow)
})
}).returnTable()
</script>