YII 1 Filter Grid Data Using Redio Button & Checkbox



view page
<label class="radio radio-inline">
<input type="radio" name="filter" checked="checked" value="all" />
<?php echo t('booking','All Types');?>
</label>
<label class="radio radio-inline">
<input type="radio" name="filter" value="both" />
<?php echo t('booking','Both');?>
</label>
<label class="radio radio-inline">
<input type="radio" name="filter" value="hotel" />
<?php echo t('booking','Hotel');?>
</label>
<label class="radio radio-inline">
<input type="radio" name="filter" value="flight" />
<?php echo t('booking','Flight');?>
</label>


$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'pt-booking-grid',

'dataProvider'=>$model->search(),
.............
.........
'columns'=>array(
array(
'name'=>'booking_type',
'type'=>'raw',
'value'=>array($this,'getBookingDetail'),
'header'=>t('general','Details'),
'filter' =>CHtml::activeDropDownList($model, 'booking_type', array(''=>t('booking','All Types'),'both'=>t('booking','Both'),'hotel'=>t('booking','Hotel'),'flight'=>t('booking','Flight'))),

),
)


javascript
<?php
Yii::app()->clientScript->registerScript('search', '
    $("input[name=\'filter\']").on("change", function(){
        var type=$(this).val();
        if(type=="all"){
            type="";
            $("select[name=\'Booking[booking_type]\'] option[value=\'\']").attr("selected","selected").change();
        }
        else{
   $("select[name=\'Booking[booking_type]\'] option[value="+type+"]").attr("selected","selected").change();
        }
});
');

?>

controller/admin 

if(isset($_GET['Booking'])){
$model->attributes=$_GET['Booking'];
}
if(isset($_GET['listType']) && !empty($_GET['listType']) && ($_GET['listType']=='hotel')){
$model->booking_type = $_GET['listType'];
}
else if(isset($_GET['listType']) && !empty($_GET['listType']) && ($_GET['listType']=='flight')){
$model->booking_type = $_GET['listType'];
}
else if(isset($_GET['listType']) && !empty($_GET['listType']) && ($_GET['listType']=='both')){
$model->booking_type = $_GET['listType'];

}


Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment