Apply selected class on checkbox checked

How it is possible to apply selected class on rows when GridView checkbox checked?

Again :)

You may use this :

http://www.yiiframework.com/doc-2.0/yii-grid-checkboxcolumn.html#$checkboxOptions-detail

For example :

‘checkboxOptions’ => function($model, $key, $index, $column) {

// whether checked is boolean

if ($model->checked) {

return [‘class’ => ‘myClass’];

} else {

return [‘class’ => ‘otherClass’];

}

}

Do you use it?

No it is not answer of my question,I want to apply a css background class on the row when I select a checkbox.

You may use jquery for it.

For example :


$('.checkbox').click (function(){

  var thisCheck = $(this);


  if ( thischeck.is(':checked') ) {

    thischeck.parent().addClass('succcess');

  } else {

     thischeck.parent().removeClass('succcess');

  }

});

Bind an onClick event to the checkbox something like:





$('#myCheckBox').click(function(e){

if ($(this).is(':checked')){

   $(this).parent().parent().addClass('classForRow');

} else {

   $(this).parent().parent().removeClass('classForRow');

}

})



Obviously the exact code around (.parent()) will depend on your DOM structure.

Thank you so much.