Source

yii-ddautofilter / README.md

DDAutoFilter

DDAutoFilter is a Yii extension to display auto-filters in a CGridView similar to MS Excel auto-filters.

It is currently working with Yii-bootstrap based Yii applications.

Installation

Extract the extension file under protected/extensions/diggindata.

Setup

Model / search Method

In your CActiveReord model's search() method, for each column that shall be displayed using auto-filters, change the $criteria line.

// Replace:
$criteria->compare('title',$this->title,true);
// ... with:
$criteria->mergeWith($this->textSearchCriteria('title', $this->title));

For date columns, use:

$criteria->mergeWith($this->dateSearchCriteria('title', $this->title));

For timestamp columns, use:

$criteria->mergeWith($this->dateSearchCriteria('title', $this->title, 'U'));

Grid View

Grid View Properties

Add some code to the CGridView afterAjaxUpdate property:

<?php $this->widget('ext.bootstrap.widgets.TbGridView', array(
    'id'=>'your-model-grid', // see below
    ...
    'afterAjaxUpdate'=>'function(){jQuery("i.autofilter").click(showAutofilterDialog)}',
    ...
    )); ?>
Grid View Columns
    'columns' => array(
        ...
        array(
            'name'=>'level',
            'class'=>'ext.diggindata.ddautofilter.DDAutoFilterDataColumn',
            'columnType'=>'number', // or 'text' or 'date' or 'bool'
            'filter => array(1=>1, 2=>2, 3=>3), // will be displayed in values select multiple control
        ),
        ...
Auto-Filter Widget

After the CGridView widget code, add:

<?php $this->widget('ext.diggindata.ddautofilter.DDAutoFilterWidget', array('gridId' => 'your-model-grid')); ?>

Donate?

If you like this extension, please consider donating a bit:

Donate with PayPal

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.