<legend id='UvV5h'><style id='UvV5h'><dir id='UvV5h'><q id='UvV5h'></q></dir></style></legend>

  • <tfoot id='UvV5h'></tfoot>
    • <bdo id='UvV5h'></bdo><ul id='UvV5h'></ul>

      1. <small id='UvV5h'></small><noframes id='UvV5h'>

        <i id='UvV5h'><tr id='UvV5h'><dt id='UvV5h'><q id='UvV5h'><span id='UvV5h'><b id='UvV5h'><form id='UvV5h'><ins id='UvV5h'></ins><ul id='UvV5h'></ul><sub id='UvV5h'></sub></form><legend id='UvV5h'></legend><bdo id='UvV5h'><pre id='UvV5h'><center id='UvV5h'></center></pre></bdo></b><th id='UvV5h'></th></span></q></dt></tr></i><div id='UvV5h'><tfoot id='UvV5h'></tfoot><dl id='UvV5h'><fieldset id='UvV5h'></fieldset></dl></div>
      2. 如何在 CheckboxColumn Gridview - Yii2 中获取选定的数据

        时间:2023-05-21

            <tbody id='tq9L3'></tbody>
          <tfoot id='tq9L3'></tfoot>

            <bdo id='tq9L3'></bdo><ul id='tq9L3'></ul>
          • <i id='tq9L3'><tr id='tq9L3'><dt id='tq9L3'><q id='tq9L3'><span id='tq9L3'><b id='tq9L3'><form id='tq9L3'><ins id='tq9L3'></ins><ul id='tq9L3'></ul><sub id='tq9L3'></sub></form><legend id='tq9L3'></legend><bdo id='tq9L3'><pre id='tq9L3'><center id='tq9L3'></center></pre></bdo></b><th id='tq9L3'></th></span></q></dt></tr></i><div id='tq9L3'><tfoot id='tq9L3'></tfoot><dl id='tq9L3'><fieldset id='tq9L3'></fieldset></dl></div>

            <small id='tq9L3'></small><noframes id='tq9L3'>

                  <legend id='tq9L3'><style id='tq9L3'><dir id='tq9L3'><q id='tq9L3'></q></dir></style></legend>
                  本文介绍了如何在 CheckboxColumn Gridview - Yii2 中获取选定的数据/项目行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在使用 checkboxColumn 获取所有选定的值/数据 Yii2 Gridview 时遇到问题.

                  我只能使用此代码在网格中获得一个:

                   'class' =>'yiigridCheckboxColumn','checkboxOptions' =>函数($model,$key,$index,$widget){返回 ['值' =>$model['item_id']];},

                  需要一些关于如何获取网格中所有值的建议...

                  这是我的代码片段控制器/视图:

                  控制器:

                  公共函数actionBulk(){$action=Yii::$app->request->post('action');$selection=(array)Yii::$app->request->post('selection');打印_r($选择);}

                  查看:

                  <?=Html::beginForm(['transjournal/bulk'],'post');?><?=GridView::widget(['数据提供者' =>$数据提供者,'有边界'=>真,'条纹'=>真,'浓缩'=>真,'悬停'=>真,'出口' =>错误的,'showOnEmpty' =>错误的,'面板'=>['after'=>Html::submitButton('<i class="glyphicon glyphicon-plus"></i> Posted', ['class' => 'btn btn-success']),],'列' =>[['类' =>'yiigridCheckboxColumn','checkboxOptions' =>函数($model,$key,$index,$widget){返回 ['值' =>$model['item_id']];},],'item_id','描述',],]);?><?= Html::endForm();?>

                  这是我的附件:

                  如何同时返回 item_id 和 description?

                  解决方案

                  您的代码有问题 'checkboxOptions' =>,您可以删除它吗?

                  <?=Html::submitButton('Send', ['class' => 'btn btn-info',]);?><?=GridView::widget(['数据提供者' =>$数据提供者,'列' =>[['类' =>'yiigridCheckboxColumn'],...],]);?><?= Html::endForm();?>

                  在控制器中:

                   公共函数 actionBulk(){$action=Yii::$app->request->post('action');$selection=(array)Yii::$app->request->post('selection');//类型转换foreach($selection as $id){$model = Post::findOne((int)$id);//进行类型转换//做你的事$model->save();//或删除}}

                  I have a problem on getting all the selected values/data Yii2 Gridview using checkboxColumn.

                  I can only get one of the value in the grid using this code:

                           'class' => 'yiigridCheckboxColumn',
                           'checkboxOptions' => function($model, $key, $index, $widget) {
                              return ['value' => $model['item_id'] ];
                           },
                  

                  Need some suggestions on how can I get all the values in the grid...

                  Here is my Code Code snippet Controller/View:

                  Controller:

                  public function actionBulk(){
                     $action=Yii::$app->request->post('action');
                     $selection=(array)Yii::$app->request->post('selection');
                     print_r($selection);
                  }
                  

                  View:

                  <?=Html::beginForm(['transjournal/bulk'],'post');?>
                  
                  <?=GridView::widget([
                     'dataProvider' => $dataProvider,
                      'bordered'=>true,
                      'striped'=>true,
                      'condensed'=>true,
                      'hover'=>true,
                      'export' => false,
                      'showOnEmpty' => false,
                      'panel'=>[
                              'after'=>Html::submitButton('<i class="glyphicon glyphicon-plus"></i> Posted', ['class' => 'btn btn-success']),
                      ],
                      'columns' => [
                      [
                          'class' => 'yiigridCheckboxColumn',
                          'checkboxOptions' => function($model, $key, $index, $widget) {
                              return ['value' => $model['item_id'] ];
                           },
                      ],
                          'item_id',
                          'description',
                      ],
                    ]);
                  ?>
                  
                  <?= Html::endForm();?> 
                  

                  Here is my attachment:

                  This is the GridView

                  This is the Result in the GridView (Selected Data only returns item_id)

                  How can I return both item_id and description?

                  解决方案

                  Issue with your code 'checkboxOptions' =>, can you remove it?

                  <?=Html::beginForm(['controller/bulk'],'post');?>
                  
                  <?=Html::dropDownList('action','',[''=>'Mark selected as: ','c'=>'Confirmed','nc'=>'No Confirmed'],['class'=>'dropdown',])?>
                  
                  <?=Html::submitButton('Send', ['class' => 'btn btn-info',]);?>
                  
                  <?=GridView::widget([
                      'dataProvider' => $dataProvider,
                      'columns' => [
                         ['class' => 'yiigridCheckboxColumn'],
                          ...
                       ],
                    ]); ?>
                  
                  <?= Html::endForm();?> 
                  

                  In Controller:

                   public function actionBulk(){
                         $action=Yii::$app->request->post('action');
                         $selection=(array)Yii::$app->request->post('selection');//typecasting
                         foreach($selection as $id){
                          $model = Post::findOne((int)$id);//make a typecasting
                          //do your stuff
                          $model->save();
                          // or delete
                        }
                      }
                  

                  这篇关于如何在 CheckboxColumn Gridview - Yii2 中获取选定的数据/项目行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:GridView 行作为链接,Yii2 中的操作列项除外 下一篇:使用图形时无法从数据库中获取数据到脚本标签

                  相关文章

                  最新文章

                • <legend id='Zd8o6'><style id='Zd8o6'><dir id='Zd8o6'><q id='Zd8o6'></q></dir></style></legend>

                      <bdo id='Zd8o6'></bdo><ul id='Zd8o6'></ul>

                    <small id='Zd8o6'></small><noframes id='Zd8o6'>

                    1. <tfoot id='Zd8o6'></tfoot>
                      <i id='Zd8o6'><tr id='Zd8o6'><dt id='Zd8o6'><q id='Zd8o6'><span id='Zd8o6'><b id='Zd8o6'><form id='Zd8o6'><ins id='Zd8o6'></ins><ul id='Zd8o6'></ul><sub id='Zd8o6'></sub></form><legend id='Zd8o6'></legend><bdo id='Zd8o6'><pre id='Zd8o6'><center id='Zd8o6'></center></pre></bdo></b><th id='Zd8o6'></th></span></q></dt></tr></i><div id='Zd8o6'><tfoot id='Zd8o6'></tfoot><dl id='Zd8o6'><fieldset id='Zd8o6'></fieldset></dl></div>