Hello,
I want to add a status filter to the admin page of blog demo but I have no idea on how to make this.
For instance, if the administrator wants to see only published posts, he could click over the dropdown at the top of the page and select Published so the system should refresh the grid/page and reloads it with the posts which status matchs the dropdown status selected. If he wants to see only Draft, the same, he clicks on the dropdown and selects Draft so the system reloads the grid with Draft posts only.
Please, any suggestions?
Thanks in advance.
Page 1 of 1
Dropdown filter on admin posts
#2
Posted 16 June 2009 - 01:16 PM
Hi scoob,
i don't know whether you're still interested or not, but i'm using such filter options for my admin pages.
I'm using the following DropDown inside the admin view to select the filter:
Inside my model i'm using these function the get the select-labels and their corresponding sql conditions (maybe since 1.0.5 it could be done nicer with named scopes):
and finally inside my controller's admin action i'm using
Hopefully this helps.
Greets,
yoshi
i don't know whether you're still interested or not, but i'm using such filter options for my admin pages.
I'm using the following DropDown inside the admin view to select the filter:
<div class="filterDropDown">
<?php echo CHtml::beginForm('','get'); ?>
Select:
<input type="hidden" name="r" value="<?php echo $this->id.'/'.$this->action->id;?>" />
<?php echo CHtml::dropDownList('cat',
isset($_GET['cat'])?(int)$_GET['cat']:0,
Post::model()->getFilterOptions(),
array('empty'=>'All', 'submit'=>'')); ?>
<?php echo CHtml::endForm(); ?>
</div>
Inside my model i'm using these function the get the select-labels and their corresponding sql conditions (maybe since 1.0.5 it could be done nicer with named scopes):
<?php public function getFilterOptions()
{
return array(
1=>'Filter1',
2=>'Filter2',
3=>'Filter3',
);
}
public function getFilterConditions()
{
return array(
1=>'FlagXY=1',
2=>'Name LIKE 'fubar'',
3=>'(test=1 AND test2=2) OR test12=3',
);
}
public function getFilterCondition($optNumber)
{
$conds = $this->getFilterConditions();
if(isset($conds[$optNumber]))
return $conds[$optNumber];
else
return '';
}
?>
and finally inside my controller's admin action i'm using
<?php
$criteria=new CDbCriteria;
if(isset($_GET['cat']) && $_GET['cat'] > 0)
{
$criteria->condition = Post::model()->getFilterCondition($_GET['cat']);
}
?>
Hopefully this helps.
Greets,
yoshi
#3
Posted 21 June 2009 - 05:00 PM
Hello, Yoshi, in fact I've already solved my problem, but thanks anyway....
your idea "getFilterConditions" is awesome!!!
thanks!!
your idea "getFilterConditions" is awesome!!!
thanks!!
Share this topic:
Page 1 of 1

Help















