我想在GridView的每一行上放置一个复选框,并将GridView与提交按钮相关联,如下图所示:
目标是每个已检查和未检查的行对数据库中的某个表执行“插入”操作。我需要帮助。
这是我现在使用的GridView代码:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'rutAlumno',
'nombreAlumno',
'apellidoAlumno',
'cursoAlumno',
//['class' => 'yii\grid\ActionColumn'],
],
]); ?>
答案 0 :(得分:0)
要将CheckboxColumn添加到yii \ grid \ GridView,请将其添加到列配置中,如下所示
['class' => CheckboxColumn::className()],
用户可以单击复选框以选择网格行。可以通过调用以下JavaScript代码来获取所选行:
var keys = $('#grid').yiiGridView('getSelectedRows');
// keys is an array consisting of the keys associated with the selected rows
了解更多Here
答案 1 :(得分:0)
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['class' => 'yii\grid\CheckboxColumn'],
'rutAlumno',
'nombreAlumno',
'apellidoAlumno',
'cursoAlumno',
//['class' => 'yii\grid\ActionColumn'],
],
]); ?>
它将为每一行生成复选框。现在正确的js脚本
$('.btn').on('click',function(e){
var selectedKeys = $('#your-grid-id').yiiGridView('getSelectedRows');
/* your code */ });