简体   繁体   English

如何用Yii隐藏cgridview过滤器?

[英]How to hide cgridview filter with Yii?

Q : how to hide the column at CGridView? 问:如何在CGridView中隐藏列?

status : I followed the posts from yii forum to hide the column as here and here . 状态:我关注yii论坛上的帖子,以隐藏此处此处的专栏。 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: 对于您的特定示例,您可以使用纯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: 但是,比使用隐藏列还有更好的方法在JavaScript中获取模型ID:

$('.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. 我想过滤器<td>仍在显示,这就是为什么您仍要显示该列的原因。 There is documentation on extending CGridColumn to be able to set htmloptions on the filter row here. 这里有有关扩展CGridColumn的文档,以便能够在此处的过滤器行上设置htmloptions。

http://www.yiiframework.com/forum/index.php/topic/20693-cgridcolumnfilterhtmloptions-missing-property/ 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. 然后,在CGridView的列定义中,您可以像调用其他任何属性一样调用此函数。

You can reuse expressions, and avoid to render additional column. 您可以重用表达式,并避免呈现其他列。

Try adding 'filterPosition'=>'none' and 'pager'=>array('header'=>'') to CGridView Widget properties like this: 尝试将'filterPosition'=>'none'和'pager'=> array('header'=>'')添加到CGridView Widget属性中,如下所示:

<?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 1.在CGridview中隐藏过滤器

.items tr.filters{ display: none;} .items tr.filters {显示:无;}

2. Hide "Advanced Search" Link 2.隐藏“高级搜索”链接

a.search-button{ display: none;} a。搜索按钮{显示:无;}

3. Hide Summary in CGridview (eg Displaying 1-10 of 13 results.) 3.在CGridview中隐藏摘要(例如,显示13个结果中的1-10。)

.grid-view .summary{ display: none;} .grid-view .summary {显示:无;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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