Reputation: 2206
I am struggling with gridview checkbox in gridview yii2. For checkbox, I can use
'class' => 'kartik\grid\CheckboxColumn',
which is extends from
'class' => 'yii\grid\CheckboxColumn',
So, the complete code is in gridview :
GridView::widget([
'id' => 'crud-datatable',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax' => true,
'columns' => require(__DIR__ . '/_columns.php'),
Which is column.php is :
return [
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function($model, $key, $index, $column) {
}
], ... /*bunch column here */
My question is, how can I checked this checkbox by pjax. Because I have a data that came from pjax like this :
$js = <<<JS
$(document).on('pjax:complete', function(data){
var datas = $('#print-sticker-keren').attr('data-print');
/* result e.g : 2297,2275,2321,2317,2315
I was wondering like function php's in_array.
*/
});
JS;
$this->registerJs($js);
Upvotes: 0
Views: 1200
Reputation: 198
in your checkboxoption check the value of checkbox if it active or inactive and add a class according to that status like
'checkboxOptions' => function($model, $key, $index, $column) {
if($model->active == 1)
$class = 'ticked';
else
$class = 'unticked';
return ['class' => $class];
}
and in your jquery function write
$(document).on('pjax:complete', function(data){
var datas = $('#print-sticker-keren').attr('data-print');
$('.ticked').attr("checked",true);
});
Upvotes: 1