I want to make drop-down table filter depend on item.id. I tried several ways but they didn't work. What I want is to filter the table depending on item.id.
It worked using this code but when I try to change the selected value or item it does not work. Please help.
$("#filterText").change(function() {
var rex = $('#filterText').val();
if (rex == "/all/") {
clearFilter()
} else {
var id = $('#' + rex);
id.hide();
// $('.toggle').filter(function () {
// return rex.test($(this).text());
// }).show();
}
});
function clearFilter() {
$('#filterText').val('');
$('.toggle').show();
}
<select id='filterText'>
@foreach (var item in Model)
{
<option value="@item.ID">@item.Title.ToString()</option>
}
</select>
<div class="panel-group" id="accordion">
<div id="faqs" class="faqs">
<table>
@foreach (var item in Model)
{
foreach (var child in item.questions)
{
<tr id="@item.ID" class="toggle faq faq-marketplace faq-authors">
<td class="togglet">@child.Title</td>
<td class="togglec">@child.Answer</td>
</tr>
}
}
</table>
</div>
</div>
$('#filterText').val('');Logical changes to values do not generate events. As such, this line of code will not generate a change event. If you want to force a change event to happen you can trigger one.$('#filterText').val('').trigger('change');I would try this first.