Yii2 GridView 复选框应用选定的类 [英] Yii2 GridView checkbox apply selected class
本文介绍了Yii2 GridView 复选框应用选定的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在yii2 gridview行上应用所选类,当复选框时.
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];
}
],
推荐答案
这段代码对我有用.
将 onClick 事件绑定到复选框,例如:
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');
}
})
显然,围绕 (.parent()) 的确切代码将取决于您的 DOM 结构.
Obviously the exact code around (.parent()) will depend on your DOM structure.
这篇关于Yii2 GridView 复选框应用选定的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文