Yii2 Gridview 获取所有分页的所有选定行 [英] Yii2 Gridview get all selected row for all pagination

查看:65
本文介绍了Yii2 Gridview 获取所有分页的所有选定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这样的 Pjax 小部件包装了我的 gridview

I wrapped my gridview with Pjax widget like this

 \yii\widgets\Pjax::begin();
    gridview
 \yii\widgets\Pjax::end(); 

为了让gridview在我点击每个分页时发出ajax请求.

in order to make the gridview make ajax request when I click on each pagination.

我也使用 ['class' =>'yii\grid\CheckboxColumn'], 也在列中.我发现当我第一次分页时,我检查了一些行,然后转到第二页并检查了一些行,但是当我回到第一页时,我检查的内容消失了.我的问题是如何保留所有分页的所有检查行

I also use ['class' => 'yii\grid\CheckboxColumn'], in column as well. and I find that when I'm on first pagination I checked some rows and then go to second page and check some rows but when I go back to first page what I've checked is gone. My question is how can I keep all checkedrow for all pagination

推荐答案

在当前条件下(Pjax、多页、yii\grid\CheckboxColumn),这是不可能的,因为它的工作方式.

With current conditions (Pjax, multiple pages, yii\grid\CheckboxColumn) it's impossible because of the way it works.

当您单击分页链接时,所有 GridView html 内容都会被来自 AJAX 响应的新内容替换.

When you click on the pagination links all GridView html content is replaced by new one that comes from the AJAX response.

很明显,上一页上所有选中的复选框都不见了.

So obviously all selected checkboxes on the previous page are gone.

解决这个问题的几种可能方法:

Few possible ways to solve that:

1) 编写自定义 javascript 和服务器端逻辑.

1) Write custom javascript and server side logic.

作为选项之一,您可以向服务器发送带有参数的 AJAX 请求,这意味着用户已选择为批量删除操作选择所有数据(或使用单独的控制器操作进行批量删除).在这种情况下,实际上我们不需要从用户那里获取选定的数据,因为我们可以简单地从数据库中获取它们(credits - Seng).

As one of the options, you can send AJAX request to server with parameter meaning that user has chosen to select all data for the bulk delete operation (or use separate controller action for bulk deletion). In this case actually we don't need to get the selected data from user, because we can simply get them from database (credits - Seng).

2) 增加每页显示的行数.

2) Increase number of displayed rows per page.

3) 使用无限滚动扩展,例如 this.

3) Use infinite scroll extension, for example this.

4) 在多次迭代中分解所需的操作:

4) Break desired action in several iterations:

  • 在第一页选择需要的行,执行操作(例如,删除).
  • 对其他页面再次重复此操作.

您可以获得这样的选定行:

You can get selected rows like that:

$('#your-grid-view').yiiGridView('getSelectedRows');

这篇关于Yii2 Gridview 获取所有分页的所有选定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆