Column search with regex not working
Column search with regex not working
Hello,
I'm trying to search a column with regex to retrieve columns with checkboxes that isn't checked. The table is rendered with razor in .Net Core.
$('input:checkbox[name="searchCheckbox"]').on('change', function () {
//build a regex filter string with an or(|) condition
var itemsNotChecked = $('input:checkbox[name="itemCheckbox"]:not(:checked)').map(function (a) {
return '^' + this.value + '$';
}).get().join('|');
//filter in column 4 (hidden column with checkboxes), with an regex, no smart filtering, not case sensitive
table.column(4).search(positions, true, false, false).draw(false);
});
TitemsNotChecked returns the correct result, in my case it found one row with value: False
<td>
<input name="itemCheckbox" type="checkbox" value="False" id="item_itemCheckbox">
<input name="item.itemCheckbox" type="hidden" value="false">
</td>
The checked ones looks like this:
<td>
<input name="itemCheckbox" type="checkbox" value="True" checked="checked" data-val="true" data-val-required="The itemCheckbox field is required." id="item_itemCheckbox">
<input name="item.itemCheckbox" type="hidden" value="false">
</td>
When I'm executing the search on table.column(1).search() it doesn't return anything, or nothing is visible in the table atleast, every row is filtered out.
The regex looks like this: "^False$"
What is the .seach() searching for? And why is nothing found?
I've tried using this instead of .map() for every available column (which in my case is unesseccary):
if ($('input:checkbox[name="searchCheckbox"]').is(':checked')) {
positions = "^((?!checked).)"; // Exclude every row that has this value in the column
}
else {
positions = "";
}
But this returns the same result..
Answers
I solved it by adding a hidden label with the vlaue and then I was able to search.