網站首頁 編程語言 正文
方法1:把合計行插入到數組中。
方法2:footer方式實現表格統計。
通過百度參考結合自己項目,做了變化。具體如下:
方法1:把合計行插入到數組中。
1.列表數據:
2? 合計行的數據合并到列表中(要做判斷,如果沒有數據,不顯示)
3?table模塊
4?page 傳參
//table與pagination組件之間的聯動
//因為table表格每頁顯示的數據被pagenation分頁默認的每頁顯示數pageSize所限制,默認為10,為了讓合計行顯示到頁面上,需+1。
const _pageSize = totalList && totalList.length == 0 ? pcPagination.pageSize : pcPagination.pageSize + 1;
//table表格需要獲取的總數據,為了讓table將后臺獲取數據和新增合計行數據全部顯示出來,需重新計算總數。
const _total = totalList && totalList.length == 0 ? pcPagination.total : pcPagination.total + parseInt(pcPagination.total/pcPagination.pageSize) + 1
//分頁設置
const paginationDefault = {
...pcPagination,
showSizeChanger: true,
current: pcPagination.current,
total: _total,
pageSize: _pageSize,
//因為與后臺規定每頁獲取的數據為10,而前端自定義追加了一條合計行,這導致當前table的每頁數據為11條,所以需要手動將分頁數據+1
//若是想顯示為['10', '20', '30', '40'],則修改每頁獲取數據為9即可。
pageSizeOptions: ['11', '21', '31', '41','51','101'],
//此處顯示的是從后臺獲取的總數據數,合計行不在其中。
showTotal: () => `共${pcPagination.total}條記錄`
}
let
4?model中傳過來的合計行數據
model 中 page 要改成默認 10條,因為合計是作為一條數據 push 進去的,且每頁都存在。后端實際返回的值是 10, 在頁面中改成了 11
效果圖:
方法2:footer方式實現表格統計。
1?table 表格中加一個 footer 屬性,表頭 showHeader 隱藏。
2、table 合計行(就是:footer 那行列表),每列的寬度要和上面列表寬度一樣。
3?合計行要做判斷,如果沒有數據,不顯示。
let status = pcDataSource && (pcDataSource.length == '0') ? {display: 'none'} : {display: 'block'};
最終效果圖:
界面UI代碼:
<Fragment>
<EditTable
resizable
bordered
loading={loading}
rowKey="penetrationId"
columns={columns}
dataSource={pcDataSource}
pagination={pcPagination}
rowSelection={{
selectedRowKeys: selectedRows.map(n => n.penetrationId),
onChange:onRowSelectChange,
}}
onChange={page => onChange(page)}
scroll={{ x: 3400 ,y:450 }}
footer={() => {
return (
<EditTable
bordered={false}
showHeader={false} // table 的 columns 頭部隱藏
columns={columns}
dataSource={footerDatasSource}
rowKey={record => Math.random()}
pagination={false}
scroll={{ x:3400 ,y:80 }}
style={status}
/>
)
}}
/>
</Fragment>
遇到問題:
1.數據列過多時候表體滾動條、和合計行滾動條不能同時滾動。
componentDidMount() {
let warp = document.getElementsByClassName("ant-table-body")[0];
// 添加滾動監聽
warp.addEventListener('scroll', this.handleScroll);
}
//監聽滾動事件
handleScroll = ()=>{
let warp = document.getElementsByClassName("ant-table-body")[0];
let wrapBottom = document.getElementsByClassName('ant-table-body')[1]
warp.addEventListener("scroll",() => {
wrapBottom.scrollLeft = warp.scrollLeft;
},true)
}
// 組件將要卸載,取消監聽window滾動事件
componentWillUnmount(){
window.removeEventListener('scroll', this.handleScroll);
}
滾動效果同步:
隱藏合計行滾動條,并對其表格:
.ant-table-footer .ant-table-body{
overflow: hidden !important;
}
.ant-table-footer{
padding-left: 46px;
}
原文鏈接:https://blog.csdn.net/weixin_44433499/article/details/117950377
相關推薦
- 2022-07-11 atom插件之·atom-minify配置支持壓縮es6
- 2022-05-05 基于PyQt5制作數據處理小工具_python
- 2022-07-02 python之NAN和INF值處理方式_python
- 2023-07-14 express+element實現上傳圖片
- 2022-09-29 關于react?ant?組件?Select下拉框?值回顯的問題_React
- 2022-08-18 R語言使用cgdsr包獲取TCGA數據示例詳解_R語言
- 2022-04-06 Python的type函數結果你知道嘛_python
- 2023-07-26 TypeScript中的模塊與命名空間
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支