Created
June 4, 2022 13:11
-
-
Save Octagon-simon/198433f360129845556516febb59c677 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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