问题
How it is possible to apply selected class on Yii2 Gridview rows,when checkbox selected.
GridView::widget([
'tableOptions' => ['class' => 'table table-striped table-hover'],
'dataProvider' => $dataProvider,
'layout' => "{items}<div class='row'><div class='pull-left'> \n {summary}</div><div class='pull-right'>{pager}</div></div>",
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function($model, $key, $index, $column) {
return ['value' => $model->jobid];
}
],
回答1:
This code work for me.
Bind an onClick event to the checkbox something like:
$("input[type='checkbox']").click(function(e){
if ($(this).is(':checked')){
$(this).parent().parent().addClass('alert-success');
} else {
$(this).parent().parent().removeClass('alert-success');
}
})
Obviously the exact code around (.parent()) will depend on your DOM structure.
来源:https://stackoverflow.com/questions/27633634/yii2-gridview-checkbox-apply-selected-class