2

I am using the YII Gridview want to show/hide columns when filtering the records Ex: If Name, City, State and phone is listing, I want checkbox to show/hide any of columns like Phone, Name in listing. Please suggest.

Thanks in advance

3
  • 1
    have you tried anything? Commented Jan 8, 2016 at 5:35
  • I can do it with data table but want to do it with Gridview. Commented Jan 8, 2016 at 5:46
  • 1
    i mean , show your effort. what you tried so far. Commented Jan 8, 2016 at 5:49

2 Answers 2

5

you can use the visible attribute of gridview column fields

<?= 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') 
        ],
        ......
Sign up to request clarification or add additional context in comments.

Comments

-1

You have to use 'visible' option for that. just pass the condition in which condition you need to visible that column. Like This :

 <?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';
    },
    ]
    ] );?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.