B
B
bizzonaru2017-01-12 12:13:54
Yii
bizzonaru, 2017-01-12 12:13:54

How to draw a separate block between each even row gridview?

It is necessary to show a separate div block in each even iteration of drawing row. It is not clear how one can refer to some internal iterator.

<?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    },                    
                    'showHeader' => false,
                    'columns' => [
                        [
                            'attribute' => 'title',
                            'format' => 'html',
                            'value' => function(Model $model) { 
                                return "
                                    <div class='container-fluid info'>
                                        <div class='row'>  
                                           // здесь отображаются данные 
                                        </div> 
                                   </div>     
                                   // Этот блок нужно показывать в каждой четной итерации
                                   <div class='container-fluid'>
                                        <div class='row'>
                                            test 
                                        </div>
                                   </div>

                                "; 
                            }
                        ],
                    ],
                ]); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-01-12
@webinar

Options:
you have function(Model $model) in value, but in fact 4 parameters are passed there ($model, $_key, $_index, $_column)
respectively you can check $_index for parity

'columns' => [
                        [
                            'attribute' => 'title',
                            'format' => 'html',
                            'value' => function($model, $key, $index) {
if(($index % 2) == 0){
 return "я четная строка";
}else{
 return "я сука не сильно четная";
}
                            }
                        ],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question