Этот код работал просто отлично.
Я изменил эту часть:
var options = new Array();
$('.checkbox input').each(function(){
options.push($(this).attr('value'));
});
на:
var options = $("input[name='option']:checked")
.map(function () { return $(this).val(); })
.get();
//I've created a `tbody` and given it a class name `.dataTable`
$("#senate-data .dataTable tr").each(function () {
var option = $(this).find(".Party").text();
var optionSelected = isIncluded(option,options);
$(this).toggle(optionSelected);
});
}
function isIncluded(x,lst) {
return lst.length === 0 || lst.indexOf(x) != -1;;
}
$("input[name='option']").on("change",updateUI);
<div class="checkbox">
<input class="form-check-input" type="checkbox" id="inlineCheckbox1" name="option" value="R">
<label class="form-check-label" for="inlineCheckbox1">Republican</label>
<input class="form-check-input" type="checkbox" id="inlineCheckbox2" name="option" value="D">
<label class="form-check-label" for="inlineCheckbox2">Democrat</label>
<input class="form-check-input" type="checkbox" id="inlineCheckbox3" name="option" value="I">
<label class="form-check-label" for="inlineCheckbox3">Independent</label>
</div>
<div id="senate-data">
<table>
<tbody>
<tr>
<th>Name</th>
<th>Party</th>
<th>State</th>
<th>Seniority</th>
<th>Perentage of votes</th>
</tr>
</tbody>
<tbody class=dataTable>
<tr>
<td>Alex</td>
<td class="Party">D</td>
<td>TN</td>
<td>11</td>
<td>80%</td>
</tr>
<tr>
<td>Ammy</td>
<td class="Party">R</td>
<td>NY</td>
<td>2</td>
<td>30%</td>
</tr>
<tr>
<td>Jammy</td>
<td class="Party">R</td>
<td>XX</td>
<td>XX</td>
<td>XX</td>
</tr>
</tbody>
</table>