• <small id='1Ou0N'></small><noframes id='1Ou0N'>

    • <bdo id='1Ou0N'></bdo><ul id='1Ou0N'></ul>

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

        Yii2:从 gridView 复选框列中获取选定的行数据到控制器中

        时间:2023-10-15
        <i id='zzm2Q'><tr id='zzm2Q'><dt id='zzm2Q'><q id='zzm2Q'><span id='zzm2Q'><b id='zzm2Q'><form id='zzm2Q'><ins id='zzm2Q'></ins><ul id='zzm2Q'></ul><sub id='zzm2Q'></sub></form><legend id='zzm2Q'></legend><bdo id='zzm2Q'><pre id='zzm2Q'><center id='zzm2Q'></center></pre></bdo></b><th id='zzm2Q'></th></span></q></dt></tr></i><div id='zzm2Q'><tfoot id='zzm2Q'></tfoot><dl id='zzm2Q'><fieldset id='zzm2Q'></fieldset></dl></div>

        • <tfoot id='zzm2Q'></tfoot>
        • <legend id='zzm2Q'><style id='zzm2Q'><dir id='zzm2Q'><q id='zzm2Q'></q></dir></style></legend>
          1. <small id='zzm2Q'></small><noframes id='zzm2Q'>

              <bdo id='zzm2Q'></bdo><ul id='zzm2Q'></ul>
                <tbody id='zzm2Q'></tbody>

                  本文介绍了Yii2:从 gridView 复选框列中获取选定的行数据到控制器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Yii2 项目中查看了页面(index.php),并且我正在使用 Kartik gridView 来显示数据

                  I've view page(index.php) in my Yii2 project, and I'm using Kartik gridView for showing the data

                  在视图的右侧,我有一个复选框列.我有一个导出按钮.我想将选定的名称(由复选框选择)导出到 name.txt 文件中.

                  On the right side of view, I've a checkbox column. And I've an Export button. I want to export the selected name (selected by checkbox) into name.txt file.

                  我终于实现了导出功能,但我不知道如何将选定的数据从视图中获取到控制器中.

                  I've finally make the export function, but I don't know how to get the selected data from view into controller.

                  我尝试了从许多论坛获得的建议,例如:

                  I've try suggestions that I got from many forums, for example:

                  我把这段 javascript 代码放在我的视图中 index.php:

                  I put this javascript code in my view index.php:

                  <script>
                  function getRows(){
                      var keys = $('#grid').yiiGridView('getSelectedRows');
                      $.post({
                          url: FakturOutController / exportAction,
                          dataType: 'json',
                          data: {keylist: keys},
                          success: function(data) {
                              alert('I did it! Processed checked rows.')
                          },
                      });
                  }
                  

                  并像这样设置导出按钮:

                  <p>
                      <button type="button" onclick="getRows()" class="btn btn-success">Export</button>
                  </p>
                  

                  但我什么也没得到,点击按钮时没有显示任何动作/反应.

                  But I got nothing, the button didn't showed any action/reaction when clicked.

                  `<?php Pjax::begin(); ?>
                  <?=
                  GridView::widget([
                      'dataProvider' => $dataProvider,
                      'tableOptions' => ['class' => 'table table-hover'],
                      'columns' => [
                          ['class' => 'yiigridSerialColumn',
                              'header' => 'No',
                          ],
                          [
                              'label' => 'Name',
                              'value' => function($data) {
                              return $data->name;
                      }
                          ],
                          ['class' => 'kartikgridCheckboxColumn'],
                      ],
                      'toolbar' => [
                          ['content' =>
                              Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], ['data-pjax' => false, 'class' => 'btn btn-default', 'title' => 'Reset Grid'])
                          ],
                          '{export}',
                          '{toggleData}'
                      ],
                      'panel' => [
                          'heading' => '<i class="glyphicon glyphicon-align-left"></i>&nbsp;&nbsp;<b>Data</b>',
                          'before' => '', //IMPORTANT
                      ],
                  ]);
                  ?>
                  <?php Pjax::end(); ?>
                  
                  <?=
                      Html::a('<i class=" glyphicon glyphicon-export"></i> Export', ['export', 'userId' => $userId], ['class' => 'btn btn-success']);
                  ?>`
                  

                  任何帮助将不胜感激.谢谢

                  Any help would be appreciated. Thanks

                  推荐答案

                  通过检查元素checkbox列你可以找到行的名称(复选框名称).它包含 id 作为 value.

                  By inspect element on checkbox column you can find name of row ( checkbox name ). it contain id as value.

                  从中您可以找到选择了多少行.

                  from that you can find how many rows are selected.

                  就我而言,我在复选框名称中得到选择[]".

                  in my case i get 'selection[]' in checkbox name.

                  例如

                  <input type="checkbox" class="kv-row-checkbox" name="selection[]" value="1">
                  

                  我编写了 jquery 代码来获取下面的选定行.

                  i write jquery code to get selected rows below.

                  <script>
                  
                      function getRows()
                      {
                          var strvalue = "";
                          $('input[name="selection[]"]:checked').each(function() {
                              if(strvalue!="")
                                  strvalue = strvalue + ","+this.value;
                              else
                                  strvalue = this.value;
                          });
                       // strvalue contain selected row by comma separated      
                      $.post({
                          url: FakturOutController / exportAction,
                          dataType: 'json',
                          data: {keylist: keys},
                          success: function(data) {
                              alert('I did it! Processed checked rows.')
                          },
                  
                  
                         });
                      }
                      </script>
                  

                  这篇关于Yii2:从 gridView 复选框列中获取选定的行数据到控制器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将 GET 参数附加到来自 &lt;form&gt; 的 URL行动 下一篇:在 yii2 gridview 中输入时进行过滤

                  相关文章

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

                  1. <legend id='lwTTW'><style id='lwTTW'><dir id='lwTTW'><q id='lwTTW'></q></dir></style></legend>
                    <tfoot id='lwTTW'></tfoot>

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