cakephp component plugin for filtering paginated model and related model data
Switch branches/tags
Pull request Compare This branch is 34 commits behind josegonzalez:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


CakePHP Filter Plugin

Paginates Filtered Records


This plugin is a fork of Jose Gonzalez's Filter component, which is something of a fork of James Fairhurst's Filter Component, which is in turn a fork by Maciej Grajcarek, which is ITSELF a fork from Nik Chankov's code.

That's a lot of forks...

This also contains a view helper made by Matt Curry.

This also uses a behavior adapted from work by Brenton to allow for HasAndBelongsToMany and HasMany relationships.

This works for all relationships.


  • Clone from github : in your plugin directory type

    git clone git://

  • Add as a git submodule : in your plugin directory type

    git submodule add git://

  • Download an archive from github and extract it in /plugins/filter


  • Include the component in your controller (AppController or otherwise)

    var $components = array('Filter.Filter');

  • Use something like the following in your index

function index() {
	$this->paginate = array_merge_recursive($this->paginate, $this->Filter->paginate);
	$posts = $this->paginate();
  • Setup your view correctly:

    • Option 1: Helper Use the helper In between the row with all the column headers and the first row of data add:

      <?php echo $filter->form('Post', array('name')) ?>

      The first parameter is the model name. The second parameter is an array of fields. If you don't want to filter a particular field pass null in that spot.

    • Option 2: Manually

      <?php echo $form->create('Post', array('action' => 'index', 'id' => 'filters')); ?>
      <table cellpadding="0" cellspacing="0">
      			<th><?php echo $paginator->sort('Name', 'name', $filter_options);?></th>
      			<th class="actions">Actions</th>
      			<th><?php echo $form->input('name'); ?></th>
      				<button type="submit" name="data[filter]" value="filter">Filter</button>
      				<button type="submit" name="data[reset]" value="reset">Reset</button>
      		// loop through and display your data
      <?php echo $form->end(); ?>
      <div class="paging">
      	<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class' => 'disabled'));?>
      	<?php echo $paginator->numbers($filter_options);?>
      	<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' =>' disabled'));?>
  • Add Behavior to model (only necessary for HABTM and HasMany):

    var $actsAs = 'Filter';

At this point, everything should theoretically work.

Initialization Tips

These different initialization options can be combined in the setup array.

  • For action(s) other than index, add a line to the controller such as this:

    $this->Filter->initialize($this, array('actions' => 'admin_index'));

  • To set it up for redirecting to the url with filters in it (which defaults to off), add a line to the controller such as this:

    $this->Filter->initialize($this, array('redirect' => true));

  • To set it up to include time in the filter, add a line to the controller such as this:

    $this->Filter->initialize($this, array('useTime' => true));


  1. Better code commenting - Done, left to help enforce the habit
  2. Support Datetime Done
  3. Support URL redirects and parsing Done
  4. Refactor datetime filtering for ranges - Mostly Done
  5. Allow the action to be configurable Done
  6. Support jQuery Datepicker Outside scope