hello , I have a problem in getting the selected row using kartik grid view. Here is my code :
[size="6"]the view:[/size]
<?= GridView::widget([
'dataProvider'=> $dataProvider,
'filterModel' => $searchInstance,
'containerOptions' => ['class' => 'instance-pjax-container'],
'export' => false,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'codebien',
'designationbien',
'codesousfamille',
'numfacture',
'dt',
['class' => 'yii\grid\CheckboxColumn'],
['class' => 'yii\grid\ActionColumn'],
],
]);?>
<?= Html::SubmitButton( 'Affecter', [ 'class' => 'btn btn-success' , 'id' =>'x']) ?>
<?php
$script = <<< JS
$(function () {
$('#x').click(function(){
$.post(
"listeaffecter",
{
pk : $('#instance-pjax-container').yiiGridView('getSelectedRows')
},
function () {
$.pjax.reload({container:'#instance-pjax-container'});
}
);
});
});
JS;
$this->registerJs($script);
?>
[size="6"]the controller : [/size]
public function actionListeaffecter(){
$searchInstance = new InstanceSearch();
$dataProvider = $searchInstance->search(Yii::$app->request->queryParams);
$pk = Yii::$app->request->post('pk'); // Array or selected records primary keys
if ($pk) {
print ("select=$pk");
}
return $this->render('vueListeAaffecter', [
'searchInstance' => $searchInstance,
'dataProvider' => $dataProvider,
]);
}
Any help plz