So I’ve asked the question on stack
Basically, I want to get the row number in the action column. I know I can do this with some jQuery and the client side, but I’d really like to do it server side. $model->id and $key both return the id and key of the model, but not the row in the table.
What do I need to replace ROW-NUMBER with?
Any suggestions would be appreciated.
GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn',
'contentOptions' => ['style' => 'font-size:20px']],
['header' => 'Blue or Red',
'class' => 'yii\grid\ActionColumn',
'template' => '{blue} {red}',
'buttons' => [
'blue' => function ($url, $model, $key) {
return bootstrap\Button::widget([
'label' => 'blue',
'id' => 'blue' . **ROW-NUMBER**,
'options' => [
'class' => 'btn-lg btn-dark votebtn',
'data-vote' => 1,
'data-row' => **ROW-NUMBER**
]
]);
},
'red' => function($url, $model, $key) {
return bootstrap\Button::widget([
'label' => 'red',
'id' => 'red' . **ROW-NUMBER**,
'options' => [
'class' => 'btn-lg btn-dark votebtn',
'data-vote' => -1,
'data-row' => **ROW-NUMBER**
]
]);
}
],
],
],
]);