server side search with getformatter
server side search with getformatter

Greetings
Well I'm using serverside processing to get my rows.
In server, I use getFormatters for changing some values.
For example in database gender column, gender stored as 1 and 0. With getFormatter I change 1 to male and 0 for female and view them like this.
Everything Ok for now.
The problem when I try to use the searchbox filter generated by datatable. When I type male, no rows rendered. I realized the search query run against datatable fields before getting formatted. (I have to search for 1 to get males rows)
Any solution or option to fix this ?
This question has an accepted answers - jump to answer
Answers
Note: Same thing with sorting when clicking on column header, it is based on original database values, not the rendered/formatted ones.
Hi @HassanDomeDenea ,
If you're using
serverSide
, your server script will need to be aware of that change and apply the search accordingly. If you'e not usingserverSide
, it should work, since the client is only aware ofmale
andfemale
.If that doesn't work, could you link to your page please. 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
@colin
Thanks for reply.
I'm using it currently on localhost.
But here are the files:
HTML:
and JS:
and PHP
and this is the Database

Here is the result:

Now when I type in search "Male", results is empty. When I type "1" in the search box, results will show males person.
Same as sort, when I filter gender column, and let suppose female are coded as (2) and males as (1), the results will show male before females, because 1 before 2, not the formatted data (F before M).
Hi,
The issue here is that the search is happening in SQL, but the formatting is happening in PHP - i.e. after the search has already happened. So unfortunately there is no way to use a getFormatter's result as part of the search term.
What you need to do instead is create an SQL VIEW which will use SQL conditional functions to do the formatting. Then you can query the view and that will be searchable by the formatted term.
Allan
@allan
Ok that's clear now.
If this feature can be added (i.e. option to make search run after formatting, not in the SQL), that would be cool.
(BTW same thing for sorting, it is based on original data from SQL, not on the php formatted fields).