Created
June 30, 2022 02:31
-
-
Save Octagon-simon/5968d1ef06381facdbb75dc46b66029c 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){ | |
| //perform case-insensitive search on the string | |
| if(tableData[ind][0].match(new RegExp(value, 'i')) || | |
| tableData[ind][1].match(new RegExp(value, 'i')) || | |
| tableData[ind][2].match(new RegExp(value, 'i')) || | |
| tableData[ind][3].match(new RegExp(value, 'i'))){ | |
| //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