Search does not work when using multiple where clauses and serverSide true
Search does not work when using multiple where clauses and serverSide true

Hi Allan,
when I use multiple where when building Editor instance:
...
->where( function ($q) use ( &$key, $value, $op, $key2, $value2, $op2 ) {
$q->or_where( $key, $value, $op );
$q->or_where( $key2, $value2, $op2 );
} )
->process( $_POST )
->json();
the general search does not work.
Maybe I need to put something like this into the anonymous function:
...
->where( function ($q) use ( ... ) {
...
$q->other_parameters( $other_parameters );
} )
...
When I use simple where clause
...
->where( $key, $value, $op )
->process( $_POST )
->json();
the general search does work without problems.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
Do you get any errors reported? Can you show me the full code you are using?
Thanks,
Allan
Hi,
unfortunately I could not catch any errors.
I simplified the code a bit, because I believe the important part is the multiple where clause (search does not work for full code nor for simplified code).
When changed to simple where clause (any of commented two), the search works as expected.
I left also JS script bare, but it has no effect on search (the search did not work with full code and it does not with simplified one):
Nothing really interesting in HTML:
As in the server's error log shows no errors?
The only thing I see that looks slightly odd is
&$key
- but$key2
is not being passed by reference. Removing the&
may help, but I doubt it.I think the key will be in the server error logs.
The other thing to check is, what is the JSON that is being returned when you have the two
or_where
conditions?Thanks,
Allan
Usually, when there is a bug in database column names or in JS editor or table, I can find errors with Chrome console.
I changed the
&$key
to$key
, but it did not help.It seems the search returns valid JSON response, but it returns more rows than it should. It is kind of hard to explain but I opened the access for you and if you have a minute, you could take a look for yourself. It might be something familiar for you.
URL: https://develop-ims.aei.sk/stocks/deliveries (login data are same as sent in PM on 29MAY2015)
Try to search for e.g. "FA259-50630-000XX", it should return only relevant rows but it does not.
Can you see what I mean?
Ah! Yes, I see what you mean. Thanks!
The problem is that the query being constructed is ending up like:
What you want is:
To do that use:
The
where_group
method will just add the braces. It isAND
by default, so that should suit your needs. The other option is to use another closure, but I think this is just as easy, although perhaps not quite as elegant.Allan
Thanks Allan, great help as always. :) This solution works well.
I just wonder – if I wanted
I would write something like:
Right?
Absolutely bob on! :-)
Allan
Thanks again! :)