美文网首页
bootstrap-table 前端(客户端)分页,默认选中某些

bootstrap-table 前端(客户端)分页,默认选中某些

作者: 田佩佩_22a7 | 来源:发表于2019-03-26 21:31 被阅读0次

代码参考:

https://github.com/pptiana/demos-tian/tree/master/src/app/bootstrap-table-page

前端技术框架:

angular4  +   bootstrap-table

目标:

制作一个table组件,前端(客户端)分页,表格支持多选,默认选中一些行,确认时取到所有选中行数据

知识点:

bootstrap-table相关参数设置与说明:

(1)前端分页:

          【sidePagination  】分页方式:client客户端分页,server服务端分页

          【responseHandler 】响应数据 ,前端分页时 return 数组类型,不能是对象等类型

(2)支持多选:

          【singleSelect 】 默认true,设置为 true 仅支持单选, 设置为  false 支持多选

(3)翻页保留其他页选中行

         【maintainSelected】默认false,设置为“true”可在翻页时保留所选行。

(4)获取选中的数据: 注意以下只能获取当前页的选中行,并不是数据表的所有选中行

          ($('#demotable').bootstrapTable('getAllSelections'));

          ($('#demotable').bootstrapTable('getSelections'));

难点:

(1)默认选中某些行

(2)取到所有选中的行数据

代码:

第一个文件:demo-table.component.html

<table id="demotable"></table>

第二个文件:demo-table.component.ts(复制代码样式太乱,故而截图)

第三个文件:test.component.html

第四个文件:test.component.ts 

表格渲染数据时通过dataUpdate通知父组件 触发recordAllData函数 记录所有行数据、并将默认选中行数据的isChecked设置为true。

onCheckAll、 onUncheckAll 、 onCheck、 onUncheck时会把当前操作行数据的isChecked属性传递给父组件,通过父组件的checkRow()将isChecked属性进行同步,这样即可实现翻页保留选中行。

save()遍历所有行 保存所有选中行数据。

第五个文件:test.json

相关文章

网友评论

      本文标题:bootstrap-table 前端(客户端)分页,默认选中某些

      本文链接:https://www.haomeiwen.com/subject/ikwigftx.html