I use ASP.NET MVC5 & JQuery. Currently I have a table setup that is filled with values from a database. Two columns: Name & Explanation
I can filter through both columns by typing and all rows that have a value that contains the input will be shown. Because the explanations are quite lengthy I would like to highlight the exact matches in the values in the cells. Think of making them bold, curved or anything like that.
Is there any way I could do this using JQuery?
EDIT1:
Filtering itself works already. I would just like to see the following to happen:
input: Book in t
Cell value: Today I am reading a Book in the garden.
The purpose of this would be to clarify where the value matches with your input.
Let me know if you have any more questions!
Input on which I filter:
<tr class="tableRow">
<td><input type="search" class="form-control tableFilter" placeholder="Filter..." /></
</tr>
Current JQuery that handles filtering:
//Table Filter based on input
$(".tableFilter").keyup(function () {
//split the current value of searchInput
var data = this.value.split(" ");
//create a jquery object of the rows
var jo = $(".table").find("tbody tr");
if (this.value == "") {
jo.show();
return;
}
//hide all the rows
jo.hide();
//Filter the jquery object to get results.
jo.filter(function (i, v) {
var $t = $(this);
var matched = true;
for (var d = 0; d < data.length; ++d) {
if (data[d].match(/^\s*$/)) {
continue;
}
var regex = new RegExp(data[d].toLowerCase());
if ($t.text().toLowerCase().replace(/(manual|auto)/g, "").match(regex) === null) {
matched = false;
}
}
return matched;
}).show();
})