antd中table展開行默認(rèn)展示,且不需要前邊的加號(hào)操作
如下所示:

前邊不顯示+,并且詳細(xì)信息默認(rèn)展開
在table中配置
<Table
expandedRowKeys={this.store.chargeTableData.map(item => item.key)} //展開的行
expandIconAsCell={false}
expandIconColumnIndex={-1}
bordered //展示邊框
defaultExpandAllRows={true} //初始時(shí)展開所有行
pagination={{ pageSize: 5 }} //分頁器
expandedRowRender={this.expandedRowRender} //額外展開的行
columns={columns} //數(shù)據(jù)
dataSource={this.store.chargeTableData} //數(shù)據(jù)數(shù)組
/>
補(bǔ)充知識(shí):antd Table 利用自己生成cell結(jié)合expandedRowKeys配置,實(shí)現(xiàn)任意cell控制展開列
因?yàn)轫?xiàng)目需要,antd實(shí)現(xiàn)一個(gè)形如這樣的表格

但是奈何翻了好幾遍api文檔并沒有發(fā)現(xiàn)這樣的東西,只好自己改造了,
首先table是這樣的
<Table
columns={this.columns}
dataSource={tableData}
bordered
pagination={false}
size='small'
expandIconAsCell={false}
expandIconColumnIndex={-1}
expandedRowRender={record=>this.expandedRowTable(record)}
expandedRowKeys={this.state.expandArray}
/>
實(shí)現(xiàn)了隱藏自帶按鈕、并確定了控制展開行的數(shù)組,
接下來就是控制數(shù)組了,
先綁定下方法
onClick={()=>this.expandTable(row)}
然后 是點(diǎn)擊cell的方法
expandTable = row =>{
const filtered = this.state.expandArray
const text = this.state.expandBtnText
if(this.state.expandArray.includes(row.key)){
filtered.splice(filtered.findIndex(element => element === row.key),1 );
this.expandTdNum(parseInt(row.key,10),'reduce')
text[parseInt(row.key,10)-1] = '詳情'
}else{
filtered.push(row.key)
this.expandTdNum(parseInt(row.key,10),'add')
text[parseInt(row.key,10)-1] = '關(guān)閉'
}
this.setState({
expandArray:filtered,
})
最后控制數(shù)組的方法
expandTdNum = (key,operation) =>{
let temp = 0
if(operation==='add'){
temp++
}else if(operation==='reduce'){
temp--
}else{
return false
}
if(key>0 && key<7){
this.setState({
firstTdNum:this.state.firstTdNum + temp,
})
}else if(key>6 && key<10){
this.setState({
middleTdNum:this.state.middleTdNum + temp,
})
}else if(key>9 && key<13){
this.setState({
lastTdNum:this.state.lastTdNum + temp,
})
}
}
以上這篇antd中table展開行默認(rèn)展示,且不需要前邊的加號(hào)操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)一個(gè)矩形標(biāo)記區(qū)域(rectangle marker)的方法
這篇文章主要介紹了vue實(shí)現(xiàn)一個(gè)矩形標(biāo)記區(qū)域 rectangle marker的方法,幫助大家實(shí)現(xiàn)區(qū)域標(biāo)記功能,感興趣的朋友可以了解下2020-10-10
Vue3 Pinia獲取全局狀態(tài)變量的實(shí)現(xiàn)方式
這篇文章主要介紹了Vue3 Pinia獲取全局狀態(tài)變量的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05
vue3中element-plus?Upload上傳文件代碼示例
這篇文章主要介紹了vue3中element-plus?Upload上傳文件的相關(guān)資料,在時(shí)間開發(fā)中上傳文件是經(jīng)常遇到的一個(gè)需求,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-08-08
Vue中對(duì)<style scoped> 中的scoped屬性解析
在Vue的單文件組件中,<style scoped> 的 scoped 屬性用于實(shí)現(xiàn)?樣式作用域隔離?,下面通過實(shí)例代碼講解Vue中對(duì)<style scoped>中的scoped屬性,感興趣的朋友一起看看吧2025-03-03
vue.js的手腳架vue-cli項(xiàng)目搭建的步驟
這篇文章主要介紹了vue.js的手腳架vue-cli項(xiàng)目搭建的步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
Vue.js的動(dòng)態(tài)組件模板的實(shí)現(xiàn)
這篇文章主要介紹了Vue.js的動(dòng)態(tài)組件模板的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-11-11

