2017-09-02 67 views
0

我在gridview yii2中的gridview複選框中掙扎。對於複選框, 我可以使用在Yii2 Gridview中檢查複選框通過pjax

'class' => 'kartik\grid\CheckboxColumn',這是從延伸

'class' => 'yii\grid\CheckboxColumn', 

所以,完整的代碼是在GridView控件:

GridView::widget([ 
     'id' => 'crud-datatable', 
     'dataProvider' => $dataProvider, 
     'filterModel' => $searchModel, 
     'pjax' => true, 
     'columns' => require(__DIR__ . '/_columns.php'), 

這是column.php是:

return [ 
[ 
    'class' => 'yii\grid\CheckboxColumn', 
    'checkboxOptions' => function($model, $key, $index, $column) { 

    } 
], ... /*bunch column here */ 

我的問題是,我怎樣才能通過pjax檢查這個複選框。因爲我有一個從pjax這樣來了一個數據:

$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); 

回答

1

在checkboxoption檢查複選框的值根據這一地位是否有效或無效,添加一個類像

'checkboxOptions' => function($model, $key, $index, $column) { 
     if($model->active == 1) 
      $class = 'ticked'; 
     else 
      $class = 'unticked'; 
     return ['class' => $class]; 

    } 

,並在您的jquery功能寫入

$(document).on('pjax:complete', function(data){ 
     var datas = $('#print-sticker-keren').attr('data-print'); 
     $('.ticked').attr("checked",true); 
    });