-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于使用server端分页,如何保存用户所有的复选框选择问题 #917
Comments
Please translate it to english |
I am poor in English,I want to achieve this demand:Checkbox selections are not being preserved when the pagination is done on server side.Would be great to be able to keep the state of the selections after the table is refreshed,I use the "maintainSelected =“true”“,but it doesn't work well |
Can you provide jsFiddle?(是否能够提供 jsFiddle 例子?) @netbuffer |
@wenzhixin 我现在用的server端分页,$('#data-bttable').bootstrapTable('getSelections')这个方法只能获得当前页用户选择的复选框,但是翻页后就不能保存状态了,怎么能实现用户翻页也能保存之前选择的复选框操作呢 |
就像你写的这样,如何能保存我每页选中的复选框呢 |
看这里的例子:http://issues.wenzhixin.net.cn/bootstrap-table/ ,也是使用 server 端分页,保存为 selections 并处理 responseHandler 就 OK 了。 |
@wenzhixin 就是看的你写的这个demo,但是我想不明白怎么存储之前的数据,还想赐教哈 |
View source: https://github.com/wenzhixin/bootstrap-table-examples/blob/master/welcome.html function responseHandler(res) {
$.each(res.rows, function (i, row) {
row.state = $.inArray(row.id, selections) !== -1;
});
return res;
} |
@wenzhixin 我这里的疑问就是selections这个变量,在翻页的时候又会被getIdSelections()方法重新赋值,那么之前的数据不就是被清空了么,我就是想不通怎么处理这个地方,应该是有个全局的数组去存储用户每一页的选择情况吧 |
对,selections 是全局变量。 |
@wenzhixin 额,那这里的问题怎么解决呢,你的demo中并没有实现这个需求,到底怎么才能实现呢,我是搞后端开发的,对前端的知识很欠缺,还请指教,谢谢了 |
https://github.com/wenzhixin/bootstrap-table-examples/blob/master/welcome.html 这里的 demo 就是实现了你说的功能: var $table = $('#table'),
selections = [];
$(function () {
$table.on('check.bs.table uncheck.bs.table ' +
'check-all.bs.table uncheck-all.bs.table', function () {
selections = $.map($table.bootstrapTable('getSelections'), function (row) {
return row.id
});
// push or splice the selections if you want to save all data selections
});
});
function responseHandler(res) {
$.each(res.rows, function (i, row) {
row.state = $.inArray(row.id, selections) !== -1;
});
return res;
} |
@wenzhixin 你应该还是不明白我的意思吧,你的demo只能实现保存用户最后选择过的,这是因为$table.bootstrapTable('getSelections')方法获取的是当前页选中的行决定的,你可以试试http://issues.wenzhixin.net.cn/bootstrap-table/welcome.html |
是的,这里只是简单的处理最后选择的,假如要记录所有的,需要对 selections 进行处理:
你试下分开对 check.bs.table,uncheck.bs.table,check-all.bs.table,uncheck-all.bs.table 事件进行处理,需要对 array 进行操作。 |
@wenzhixin 嗯,我就是这里想不清楚,想了两天啦,可以详细说明下这个地方怎么处理么,非常感谢! |
那你等等,我晚些有时间再写个完整的 demo 到 https://github.com/wenzhixin/bootstrap-table-examples 上,你那边假如实现了可以提交 pull request 到 example 上。 |
Added example: Maintain selected on server side: http://issues.wenzhixin.net.cn/bootstrap-table/#issues/917.html |
你好,我是用js实现的表格,也通过你的例子实现了分页保存选择的数据。可是在处理数据的时候,他一直不能显示选中状态,row.status已经改为true页面上也没有选中,请问这是什么原因呢? //取消选中事件
` |
不好意思,我想我弄明白是怎么回事了。 我写了一个示例,按照你的思路,实现了方法,需要的可以看看http://blog.csdn.net/github_36086968/article/details/60773900#comments |
你好,我想请问一下,怎么把 selections 的值获取到呢,我可以把值打印出来,但是我想在别的地方对selections进行操作,会显示undefined,存到cookie里再拿出来么? |
如果client端分页,如果处理复选框问题。望指教,谢谢了。 |
@zhujinjun 用 |
你好,我有旧版本js引用,单独点击一个的时候不报错,在全选的时候报错了,获取不然rows,请问这是怎么回事呢? 如果不改变版本引用,我想获取当前页的数据,应该用什么方法呢? |
还是建议升级版本吧 |
Ive checked that the demo doesnt work properly. #917 Goto page 1 of the list of results. If you check the very top checkbox, it selects all. As expected. Uncheck this and then it unselects all. As expected. Goto the next page in the pagination navigation, then browse back to the same page and the list is still checked - we should expect the list to be Unchecked. If you select a single item, and unselect - this is done correctly, its just with the Unselect all - the rows are not removed from the selections array. |
我使用这种方式实现了选中效果,但是使用getAllSelections方法,不能获取所有选中的数据,只能获取到当前页选中的数据,前一页或者后一页的处于选中状态的数据获取不到。maintainSelected这个属性也设置为true。 |
@jingshenbusi6530 最新版本已经更新为 |
打不开 |
这个属性怎么使用 |
看下文档和例子 @ghostsatan |
http://issues.wenzhixin.net.cn/bootstrap-table/ 这个地方打不开 请问 文档的连接方便给一个吗 |
维护之前很老的项目 估计版本比较老 代码没法重构
不知道该在什么地方添加这个 分页保存 多选的问题 |
你可以看下这个例子,加个参数:https://examples.bootstrap-table.com/#issues/917.html |
根据这例子尝试了一下 `
这个地方 在第一页的时候选中两条数据 分页到第二页 然后在第二页返回第一页 打印出的row 显示出 第一页多选的两条数据的row.state 是true 但是页面上却不显示选中的样式 求解 |
解决了 ` function stateFormatter(value, row, index) { 多谢 |
比如我现在 第一页选中了2个 第二页选中了 4个 我点击提交
|
@ghostsatan server 分支只能获取当页的,多出来的要自己管理。 |
$table.on('check.bs.table uncheck.bs.table ' +
'check-all.bs.table uncheck-all.bs.table', function () {
$remove.prop('disabled', !$table.bootstrapTable('getSelections').length);
getIdSelections方法只能获得当前页面的选择,但是翻页后就会丢失之前保存的数据,我看到您的示例代码中给予了提示,但是具体怎么实现保存用户所有的复选框选择还是没有思路,能否给予点指引呢
The text was updated successfully, but these errors were encountered: