[PHP Lib]When ordering by field only return results that have a value in field
[PHP Lib]When ordering by field only return results that have a value in field
Hello,
I've been trying to figure out how best to implement this.
I'd like to add a new field A
. A will contain a numeric value. When sorting by A
I would like to avoid record that have no value in A
from appearing. I haven't been able to find anything in the PHP library's API that seems to achieve this cleanly.
Any help is appreciated!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Sounds like you want a search? How about:
table.column(0).search('.+', true, false);
. That will search for one or more characters in the string of column index 0.Allan
Well this would only be enforced when that specific column is being sorted on. That's where my hangup is.
By default showing records with a blank value in field
A
is fine, but if the user is sorting by fieldA
then the records should have a value.The issue I'm trying to avoid is when sorting a column by ascending(?) the blank values will appear at the top. In my case that would be thousands of records which kind of renders sorting in that direction pointless.
I was also hoping to handle this server-side via Editor's PHP API but that's not a requirement.
Have a look at this blog post which introduces a search plug-in you can use to keep an empty string (or anything else) always at the bottom of the table.
Allan
Will do thanks as always Allan!
Alan,
I got a chance to try this out but unfortunately this doesn't work for my case.
Since I'm using the Editor server-side PHP library only a subset of records are given to the client to display. e.g. if my
pageLength
is set to 10 the client will only get 10 records to show and as such the sorting plugin you linked would only apply to those 10 records.Ah - if you are using server-side processing, then yes, that wouldn't work since its client-side.
For server-side processing (if client-side isn't an option), you'd need to implement this via SQL somehow. Its probably possible, but not something I've attempted I'm afraid.
Allan
That's about what I suspected. I just wanted to make sure there wasn't some part of the API that I was overlooking before I started to shoehorn this in.
Thanks!