[英]Checkbox column not Working in yii2 gridview with Modal
I have a gridview . 我有一个gridview。 It displays the departments available in a college.
它显示了大学中可用的部门。 When I click the row it populate the modal and Its shows the lecturer available for the selected department in kartik gridview .
当我单击该行时,它将填充模态,并且在kartik gridview中显示可用于所选部门的讲师。
In that I am using the kartik/grid/CheckboxColumn. 在这种情况下,我正在使用kartik / grid / CheckboxColumn。
But when I click the Checkbox and get the selected rows through javacript, It doesn't return primary key associated with the record. 但是,当我单击“复选框”并通过javacript获取选定的行时,它不会返回与记录关联的主键。 If I execute the gridview without modal , then it works fine
如果我在不使用模式的情况下执行gridview,那么它将正常
$this->registerJs("
$('#lect-logout').click(function() {
var key = $('#w0-container').yiiGridView('getSelectedRows');
alert(key);
$.post(
'?r=lec-logout/logout',
{
id: $('#w0').yiiGridView('getSelectedRows'),
},
function (data) {
alert("ok");
}
);
}); });
"); “);
How to use that checkbox with the modal. 如何将该复选框与模式一起使用。 Even I click select all option in checkbox.
即使单击复选框中的“全选”也是如此。 It doesn't select all the rows.
它不会选择所有行。
public function actionIndex()
{
$searchModel = new CollegeSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
}
public function actionLecture()
{
$model = new Accounts();
if ($model->load(Yii::$app->request->post())) {
return $this->redirect(['index']);
}
else{
$searchModel = new LectureSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->renderAjax('lecture', ['searchModel' => $searchModel,'dataProvider' => $dataProvider]);
}
}
index.php index.php
<?= GridView::widget([
'dataProvider' => $dataProvider,
'rowOptions' => function($model, $key, $index, $grid) {
return ['id' => $model['account_id'], 'onclick' => 'getrow(this.id)'];
},
'columns' => [
'displayname',
],
]); ?>
<?php Modal::begin([
'id' => 'show-agents-modal',
'size' => 'modal-lg',
'header' => '<h4 class="modal-title">View</h4>',
]);
Modal::end(); ?>
Lecture.php Lecture.php
<div class="pull-right">
<?= Html::Button('Logout',['class'=>'btn btn-primary','id'=>'lect- logout']); ?>
</div>
<br>
<?= GridView::widget([
'dataProvider' => $dataProvider,
// 'filterModel' => $searchModel,
'columns' => [
'first_name,
['class' => 'kartik\grid\CheckboxColumn'],
],
]); ?>
If you want to use yii\\grid\\CheckboxColumn then try this : 如果要使用yii \\ grid \\ CheckboxColumn,请尝试以下操作:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function($model, $key, $index, $column) {
return ['value' => $model->your_id];
},
],
.
.
])?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.