Server-side checkbox filter
Server-side checkbox filter

Hello, this is my table with 2 checkboxes: live.datatables.net/xasihece/1/edit
I'm trying to filter data in my table with these two checkboxes (will be more checkboxes and date-picker in the future). I'm using the php server_processing php and ssp.class.php. I found some comments about custom filtering in the ssp.class.php file, but there is no example how to do it and there is no example also in the DataTables forum or internet.
I know that I need to modify the WHERE conditoin in the ssp.class.php when checkbox is selected, but I'm completely lost how to do it. Thank you in advance.
Answers
Hi @culter ,
This thread here should sort you out, it's asking the same thing,
Cheers,
Colin
Thank you, Colin, the thread is very helpful. But still if I may ask you some questions..
I'm sending the filter state from index.php as this:
I have read in the ssp.class.php comments, that I need to use the complex function to add additional 'where' conditions to the SQL queries, so I changed the
to
Do I need to apply more changes to server_processing.php or just this one?
Next, as it is written in the ssp.class.php before the complex function I think I need to modify 'All condition' form, but I have no idea how to do it. Can you provide some example, please? Thank you.
Yes, you need to actually pass a
where
condition as well. It isn't currently doing anything with yourmojaF
variable.If you look at the code for the SSP class you will see that there are two additional optional arguments for the
complex
method, which can be used to set the condition.Allan
Thank you, Allan. I'm sorry, but I have another two questions:
Is it possible to check if the mojaF variable is sent to server_processing script?
Could you please specify how to set the condition in one of the optional arguments? Or is there some example? I prefer to use the $whereAll, because I will need to restrict records by login id in the future.
Thank you!
You can use PHP's
isset
method for that - e.g.:Allan
Thanks Allan, I have added the isset method to the 'complex' function in ssp.class.php, but I'm not sure if it's the right place. Could you please confirm? And the fieldName is the column name?
I have set the mojaF right in the "data": function (d) { d.mojaF = 1; } for testing purposes, but all I got is "No data available in table" with no error
Thank you, I appreciate your help.
I have corrected my code and now the error message is:
Why it is looking for 'Array' column?
In Apache's error log is this php notice:
Ok, I was able to set the filter in ssp.class.php as follows:
It is connected with the d.mojaF in the index.php as follows:
So when I change d.mojaF variable in the function(d), the sql query will change appropriately, but how to get the checkbox state to the function(d)? Thanks
I'd actually suggest you do the
isset
in your main script - not in the ssp class - e.g.:Allan
Thanks, I rewrote it in server_processing.php as follows:
and this is the function for first checkbox and DataTable (index.php):
</script>
When I change the value of check01 (2nd script, line 2) manually, it is working fine and the table displays filtered data, but when I click on the checkbox, the table doesn't refresh with the filtered data and no change is visible.
In
myCheckFunc()
are you wanting the Datatables to be refreshed? If so you can try eitherdraw()
orajax.reload()
to send a request to the server fro fresh data.Kevin
Thanks Kevin, I have posted complete code of myCheckFunc(), so I'm not waiting for the DataTables refresh. Recently I tried to use ajax.reload() as follows
but with no effect
Tomorrow I will try to use draw(). Hope it will work. Thank you.
Ok,
$('#example').DataTable().ajax.reload();
is working and the table is redrawn, but nothing changed, because the variable check01 from myCheckFunc() did'nt get to dataTable
My code is as follows:
The myCheckFunc() is out of DataTable(). Maybe it's problem with local/global variables. I tried to add the myCheckFunc() in the $(document.ready(function() {}, but I've got and error, that myCheckFunction in line 1 is not defined
Do you have some ide how to get the value of check01 variable to the function in DataTable?
Thank you
In line 9 you have
var check01 = 0;
. Remove thevar
part. This is defining a local scope variable for themyCheckFunc
function.Kevin
I owe you 2 beers now. Fantastic! I have my first checkbox filter, many thanks to all of you. Now the other 10 checkboxes and it's done.
Have a nice day.
Hello, Culter This is exactly what I'm looking. I was trying to create checkbox filter using serverside but its not working this one
Can you share me the complete codes of your custom filter from the checkbox to js and serverside.php please

Hi @hashsalacop ,
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi colin here is my sample but i dont know how to work the serverside.php on this.this are the just a simple code on my data the javascript and the html. this one
Hi @hashsalacop ,
The problem is that you're using regular expressions, which the supplied server-side scripts don't support. This thread here has some discussion on it.
Cheers,
Colin
I dont really get it.. i was trying to solve this for 2 weeks and up until now i can't solve it. can you give me a example there is no response on the ajax.