Skip to content

Commit

Permalink
Add filterSelector to CGridView
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyMaster committed Oct 27, 2012
1 parent 9154719 commit 58a4d3d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
7 changes: 5 additions & 2 deletions framework/zii/widgets/assets/gridview/jquery.yiigridview.js
Expand Up @@ -76,6 +76,8 @@
settings.updateSelector = settings.updateSelector
.replace('{page}', pagerSelector)
.replace('{sort}', sortSelector);
settings.filterSelector = settings.filterSelector
.replace('{filters}', inputSelector);

gridSettings[id] = settings;

Expand All @@ -96,7 +98,7 @@
});
}

$(document).on('change.yiiGridView keydown.yiiGridView', inputSelector, function (event) {
$(document).on('change.yiiGridView keydown.yiiGridView', settings.filterSelector, function (event) {
if (event.type === 'keydown') {
if( event.keyCode !== 13) {
return; // only react to enter key
Expand All @@ -110,7 +112,7 @@
return;
}
}
var data = $(inputSelector).serialize();
var data = $(settings.filterSelector).serialize();
if (settings.pageVar !== undefined) {
data += '&' + settings.pageVar + '=1';
}
Expand Down Expand Up @@ -366,6 +368,7 @@
});
return checked;
}

};

$.fn.yiiGridView = function (method) {
Expand Down
27 changes: 23 additions & 4 deletions framework/zii/widgets/grid/CGridView.php
Expand Up @@ -235,10 +235,26 @@ class CGridView extends CBaseListView
* @since 1.1.1
*/
public $loadingCssClass='grid-view-loading';
/**
* @var string the jQuery selector of filter input fields. Defaults to '{filters}', that
* will be replaced with selector for internal grid filters.
*
* @since 1.1.13
*/
public $filterSelector='{filters}';
/**
* @var string the CSS class name for the table row element containing all filter input fields. Defaults to 'filters'.
* @see filter
* @since 1.1.1
*
* Note: if this value is empty an exception will be thrown.
*
* Example (adding a custom selector to the default one):
* <pre>
* ...
* 'filterSelector'=>'{filters}, #myfilter',
* ...
* </pre>
*/
public $filterCssClass='filters';
/**
Expand Down Expand Up @@ -289,6 +305,8 @@ public function init()

if(empty($this->updateSelector))
throw new CException(Yii::t('zii','The property updateSelector should be defined.'));
if(empty($this->filterSelector))
throw new CException(Yii::t('zii','The property filterSelector should be defined.'));

if(!isset($this->htmlOptions['class']))
$this->htmlOptions['class']='grid-view';
Expand All @@ -315,7 +333,7 @@ protected function initColumns()
{
if($this->dataProvider instanceof CActiveDataProvider)
$this->columns=$this->dataProvider->model->attributeNames();
elseif($this->dataProvider instanceof IDataProvider)
else if($this->dataProvider instanceof IDataProvider)
{
// use the keys of the first row of data as the default columns
$data=$this->dataProvider->getData();
Expand Down Expand Up @@ -386,7 +404,8 @@ public function registerClientScript()
'tableClass'=>$this->itemsCssClass,
'selectableRows'=>$this->selectableRows,
'enableHistory'=>$this->enableHistory,
'updateSelector'=>$this->updateSelector
'updateSelector'=>$this->updateSelector,
'filterSelector'=>$this->filterSelector
);
if($this->ajaxUrl!==null)
$options['url']=CHtml::normalizeUrl($this->ajaxUrl);
Expand Down Expand Up @@ -455,7 +474,7 @@ public function renderTableHeader()

echo "</thead>\n";
}
elseif($this->filter!==null && ($this->filterPosition===self::FILTER_POS_HEADER || $this->filterPosition===self::FILTER_POS_BODY))
else if($this->filter!==null && ($this->filterPosition===self::FILTER_POS_HEADER || $this->filterPosition===self::FILTER_POS_BODY))
{
echo "<thead>\n";
$this->renderFilter();
Expand Down Expand Up @@ -535,7 +554,7 @@ public function renderTableRow($row)
$data=$this->dataProvider->data[$row];
$class=$this->evaluateExpression($this->rowCssClassExpression,array('row'=>$row,'data'=>$data));
}
elseif(is_array($this->rowCssClass) && ($n=count($this->rowCssClass))>0)
else if(is_array($this->rowCssClass) && ($n=count($this->rowCssClass))>0)
$class=$this->rowCssClass[$row%$n];
else
$class='';
Expand Down

0 comments on commit 58a4d3d

Please sign in to comment.