I have some custom buttons in the actionColumn of gridview in Yii2. I need to add the row number to the button data. Here's what I have...
GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yiigridSerialColumn',
'contentOptions' => ['style' => 'font-size:20px']],
['header' => 'Blue or Red',
'class' => 'yiigridActionColumn',
'template' => '{blue} {red}',
'buttons' => [
'blue' => function ($url, $model, $key) {
return bootstrapButton::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 bootstrapButton::widget([
'label' => 'red',
'id' => 'red' . **ROW-NUMBER**,
'options' => [
'class' => 'btn-lg btn-dark votebtn',
'data-vote' => -1,
'data-row' => **ROW-NUMBER**
]
]);
}
],
],
],
]);
What do I need to put in place of ROW-NUMBER to get the row each button is in?
question from:https://stackoverflow.com/questions/65928145/how-do-i-access-row-number-in-yii2-gridview-actioncolumn