Enhanced filters in Pagination - how?

Asked by Brian Rippon

The Pagination plugin is great, but I'd like to be able to provide enhanced search filter functionality beyond "a LIKE '%x%' OR b LIKE '%x'...". For example, 'Power > 1000', or 'Price > 2000 AND Price < 4000'.

Is there a way that I can hook extra form fields/filters into Pagination, or is it a case of building a new plugin based on it?

Question information

English Edit question
PHPDevShell Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
TitanKing (titan-phpdevshell) said :

You can modify the query just as you wish... look at the database object for more information, but what it comes down to, is simply pass variable to your sql like this:

class SomeQuery extends PHPDS_query
 protected $sql = "
   some_column, some_column2, Price
   Price > %u AND Price < %u

 public function invoke($parameters)
  // Do all the invoke for pagination here...

  // Now push replacements for %u
  $price1 = 2000;
  $price2 = 4000;

  $query = $pagination->query($this->sql, $price1, $price2);


Now just add dynamic data as you wish...

Revision history for this message
TitanKing (titan-phpdevshell) said :

Then I see you ask about forms...

Inside your view create the form you wish for, the submit button should be called 'save' and then the search field should be called 'search_field', then the rest of the filter form can be whatever you choose. Then just pass the rest of the forms filters as parameters to the query.

Also note that, in above example we already used WHERE, so you might want to explicitly tell the query the rest of the query should be :
$pagination->condition = 'AND'; // This should be automatically detected though.

Revision history for this message
Brian Rippon (brian-rippon) said :

Sorry, should have said I was happy about modifying $sql to contain my WHERE clauses, although I hadn't thought to add the parameters to $pagination->query(). And it was how to modify the form that troubled me.

I'm still thinking about your reply, but I assume I have to code my own form in the view, instead of $pagination->searchForm()? I'm not yet familiar enough with the code to understand how this function works. I'm also trying to figure out the significance of the name 'save' for the submit button...

I'm getting there - many thanks.

Revision history for this message
TitanKing (titan-phpdevshell) said :

Hi Brian,

Yes, you create your own form in the view instead of using the standard auto drawn one. The reason why I say you need to ha a $post['save'] and $post['search_field'] available is because the standard filter plugin looks for this and uses this to do the search query if search field is used. This is so that the standard functionality of your form still works.

Can you help with this problem?

Provide an answer of your own, or ask Brian Rippon for more information if necessary.

To post a message you must log in.