Yii2 GridView checkbox apply selected class

别等时光非礼了梦想. 提交于 2019-12-08 06:15:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!