【问题标题】:Yii Gridview show/hide columns from interface when filtering the recordsYii Gridview 在过滤记录时显示/隐藏界面中的列
【发布时间】:2016-01-08 17:31:42
【问题描述】:

我正在使用 YII Gridview 想要在过滤记录时显示/隐藏列 例如:如果列出姓名、城市、州和电话,我希望复选框显示/隐藏列表中的电话、姓名等任何列。 请提出建议。

提前致谢

【问题讨论】:

  • 你尝试过什么吗?
  • 我可以用数据表做,但想用 Gridview 做。
  • 我的意思是,展示你的努力。到目前为止你尝试了什么。

标签: yii2 yii-extensions yii2-advanced-app


【解决方案1】:

你可以使用gridview列字段的可见属性

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'your_attribute1',
        ....
        [
            'label' => 'your_labe',
            'attribute_n' => 'your_attribute',
             'visible' => ( $your_condition == 'value_for_visible') 
        ],
        ......

【讨论】:

    【解决方案2】:

    您必须为此使用“可见”选项。只需传递您需要显示该列的条件。像这样:

     <?php echo GridView::widget( [
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        ['attribute'=>'your_column',
        'visible'=> if ( $data->field_name == "some_value" ) ? true : false,
        'value'=>function( $data ) {
            return !empty( $data->your_column ) ? $data->your_column : '0.5';
        },
        ]
        ] );?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 2015-10-29
      • 1970-01-01
      • 2014-09-09
      • 2012-12-28
      • 1970-01-01
      相关资源
      最近更新 更多