简体   繁体   中英

How to hide cgridview filter with Yii?

Q : how to hide the column at CGridView?

status : I followed the posts from yii forum to hide the column as here and here . but in my grid view the right column didn't hide. it is showing as a blank.

This is my view code

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'acc-recei-grid',
    'dataProvider'=>$model->search_arlist(),
    'filter'=>$model,
    'columns'=>array(
        array('name' => 'acc_category_id',
               'value'=>'(isset($data->acccategories->name)) ? CHtml::encode($data->acccategories->name) :""',
               'filter'=>CHtml::listData($acccategory, 'id', 'name'),
        ),
        //'customer_id',
        //'date',
        array('name' => 'job_id',
               'value'=>'(isset($data->jobs->name)) ? CHtml::encode($data->jobs->name) :""',
               //'filter'=>CHtml::listData($job, 'id', 'name'),
        ),

        array(
            'class'=>'CButtonColumn',
            'template'=>'{select}',
            'buttons'=>array
            (
                'select' => array
                (
                    'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/icon_select.gif',
                    'options'=>array('style'=>'width:10px; border:none'),
                    'click'=>'function(){
                        var itemID = $(this).parents(\'tr\').find(\'.recei-id\').text();
                        $("#AccPaymentRecei_acc_recei_id").val(itemID); 
                        $("#accreceilist").dialog("close");

                    }',
                ),      
            ),
        ),
        array(
            'type'=>'raw',
            'value'=>'$data->id',
            //'filter'=>array('style'=>'visible:none'), 
            'headerHtmlOptions'=>array('style'=>'width:0px; display:none; border:none; textdecoration:none'),
            'htmlOptions'=>array('style'=>'display:none; border:none;', 'class'=>'recei-id'),  
            'header'=>false,
            'filter'=>false,
        ),
    ),
)); ?>

but the grid view show like this

在此处输入图片说明

====== update

<div id="acc-recei-grid" class="grid-view">
<div class="summary">Displaying 1-1 of 1 result(s).</div>
<table class="items">
<thead>
<tr>
<th id="acc-recei-grid_c0"><a href="/mmaig_ceo/ceo-control-system/accRecei/Accreceilist?AccRecei_sort=acc_category_id">Acc Category</a></th><th id="acc-recei-grid_c1"><a href="/mmaig_ceo/ceo-control-system/accRecei/Accreceilist?AccRecei_sort=job_id">Job</a></th><th class="button-column" id="acc-recei-grid_c2">&nbsp;</th><th style="width:0px; display:none; border:none; textdecoration:none" id="acc-recei-grid_c3">&nbsp;</th></tr>
<tr class="filters">
<td><select name="AccRecei[acc_category_id]">
<option value=""></option>
<option value="1">asdfasdf</option>
</select></td><td><input name="AccRecei[job_id]" type="text" maxlength="11" /></td><td>&nbsp;</td><td>&nbsp;</td></tr>
</thead>
<tbody>
<tr class="odd"><td>asdfasdf</td><td>asdf</td><td class="button-column"><a style="width:10px; border:none" class="select" title="select" href="#"><img src="/mmaig_ceo/ceo-control-system/protected/assets/images/gridview/icon_select.gif" alt="select" /></a></td><td style="display:none; border:none;" class="recei-id">1</td></tr>
</tbody>
</table>
<div class="keys" style="display:none" title="/mmaig_ceo/ceo-control-system/AccRecei/Accreceilist"><span>1</span></div>
</div>

For your particular example you can use pure css:

#acc-recei-grid td:last-child, #acc-recei-grid th:last-child {display: none}

But there is better way to take model id in javascript than using hidden column:

$('.yourButtonColumnCssClass').live('click', function() {
    var id = $.fn.yiiGridView.getKey(
        'acc_category_id',
        $(this).closest('tr').prevAll().length 
    );
    $("#AccPaymentRecei_acc_recei_id").val(id); 
    $("#accreceilist").dialog("close");
});

Im guessing the filter <td> is still showing which is why you are getting the column still showing. There is documentation on extending CGridColumn to be able to set htmloptions on the filter row here.

http://www.yiiframework.com/forum/index.php/topic/20693-cgridcolumnfilterhtmloptions-missing-property/

In your model you can define function as :

function getCategoryTextWithId()
{
  return "<span  style='display:none'>$this->id</span>" . ...
}

Then in your column definition for CGridView you can call this function same as any other property.

You can reuse expressions, and avoid to render additional column.

Try adding 'filterPosition'=>'none' and 'pager'=>array('header'=>'') to CGridView Widget properties like this:

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'model-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'ajaxUpdate'=>false,
'filterPosition'=>'none',
'template'=>'{items}{summary}{pager}',
'pager'=>array('header'=>''),
'columns'=>array(
    'id',
    'name',
    'description',
    array(
        'class'=>'IButtonColumn',
    ),
),
)); ?>

1. Hide Filter in CGridview

.items tr.filters{ display: none;}

2. Hide "Advanced Search" Link

a.search-button{ display: none;}

3. Hide Summary in CGridview (eg Displaying 1-10 of 13 results.)

.grid-view .summary{ display: none;}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM