Answer the question
In order to leave comments, you need to log in
How to do a search on the columns of an HTML table?
Hello! There is a site on ModX and a table with data in HTML format on one of the pages. Tell me how to search through the columns of this table so that when you enter it in a text field, the results of matching the query are displayed immediately on the page?
I tried to do it in AngularJS, but there must be a simpler solution.
Answer the question
In order to leave comments, you need to log in
function tableSearch() {
var phrase = document.getElementById('**сюда id поисковой строки**');
var table = document.getElementById('**сюда id столбца**');
var regPhrase = new RegExp(phrase.value, 'i');
var flag = false;
for (var i = 1; i < table.rows.length; i++) {
flag = false;
for (var j = table.rows[i].cells.length - 1; j >= 0; j--) {
flag = regPhrase.test(table.rows[i].cells[j].innerHTML);
if (flag) break;
}
if (flag) {
table.rows[i].style.display = "";
} else {
table.rows[i].style.display = "none";
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question