Yii2 GridView checkbox apply selected class

2019-05-31 14:31发布

问题:

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.



标签: yii2