I'm using DataTables with server-side processing to display tens of thousands rows. I need to filter these data by checkboxes. I was able to make one checkbox which is working fine, but I don't know how to add multiple checkboxes to work together. I found similar solution here, but my skills doesn't allow me to modify it to my needs:( Here is what I have tried..
My index.php:
Statuses:<br>
<input type="checkbox" id="0" onclick="myCheckFunc()" name="statuses">Open<br>
<input type="checkbox" id="1" onclick="myCheckFunc()" name="statuses">Closed<br>
<input type="checkbox" id="2" onclick="myCheckFunc()" name="statuses">Solved<br>
<script>
var idsa = 5;
$('input[name=statuses]').click(function(){
idsa = [];
$('input[name=statuses]:checked').each(function() {
idsa.push($(this).attr('id'));
});
idsa = idsa.join(",");
console.log("idsa fcia: " + idsa);
$('#example').DataTable().ajax.reload();
});
</script>
The idsa variable is initially set to 5, which means all statuses(no checkbox checked) then send to server side script with it's format(d) function (this part is working fine). This is how I modify sql query in server side script:
if ($_GET['idsa'] == 5){
$idsa = "0,1,2";
} else { if (isset($_GET['idsa'])) {
$idsa = "('" . str_replace(",", "','", $_GET['idsa']) . "')"; }
}
$whereAll = "STATUS IN ($idsa)";
EDIT: Now after click on first of these three checkboxes, the data are filtered correctly (Open tickets with status 0), but uncheck don't bring back the initial state with all data. When I click on other two, the data are filtered, but when I uncheck, the data are fitered byt first filter (Open). When I click two or more checkboxes, I get this error:
An SQL error occurred: SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)