Skip to content

cakephp component plugin for filtering paginated model and related model data

Notifications You must be signed in to change notification settings

mcurry/cakephp-filter-component

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Filter Paginated Indexes using the Filter Component Plugin

Background

This component is something of a fork of James Fairhurst's Filter Component (http://www.jamesfairhurst.co.uk/posts/view/cakephp_filter_component/), which is in turn a fork by Maciej Grajcarek (http://blog.uplevel.pl/index.php/2008/06/cakephp-12-filter-component/) which is ITSELF a fork from Nik Chankov's code at http://nik.chankov.net/2008/03/01/filtering-component-for-your-tables/ .

That's a lot of forks...

Filters hasOne and belongsTo relationships (I prefer selects from dropdowns, but to each their own).

Installation

  • Clone from github : in your plugin directory type git clone git://github.com/josegonzalez/filter-component.git filter
  • Add as a git submodule : in your plugin directory type git submodule add git://github.com/josegonzalez/filter-component.git filter
  • Download an archive from github and extract it in /plugins/filter

Usage

  1. Include the component in your controller (AppController or otherwise) var $components = array('Filter.Filter');
  2. Use something like the following in your index function index() { $filterOptions = $this->Filter->filterOptions; $posts = $this->paginate(null, $this->Filter->filter); $this->set(compact('filterOptions', 'posts')); }
  3. Setup your view correctly: Option 1: Use the helper In between the row with all the column headers and the first row of data add: 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 create('Post', array('action' => 'index', 'id' => 'filters')); ?>

// loop through and display your data
sort('Name', 'name', $filterOptions);?> Actions
input('name'); ?> Filter Reset
end(); ?>

Page Links

prev('<< '.__('previous', true), $filterOptions, null, array('class' => 'disabled'));?> | numbers($filterOptions);?> next(__('next', true).' >>', $filterOptions, null, array('class' =>' disabled'));?>

At this point, everything should theoretically work.

TODO:

  1. Better code commenting
  2. Refactor datetime filtering for ranges
  3. Support jQuery Datepicker
  4. Allow the action to be configurable

About

cakephp component plugin for filtering paginated model and related model data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%