需求要带回显,用了reserve-selection+row-key
<el-table ref="selTable" v-loading="selectTableLoading" border :data="allData[this.selectDataPageInfo.page]" size="small" style="width: 100%;" height="400" :row-key="(row) => row.id" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" :reserve-selection="true" />
<el-table-column prop="materialName" label="备品名称" />
<el-table-column prop="materialTypeName" label="备品类型" />
<el-table-column prop="materialBrand" label="备品品牌" />
<el-table-column prop="materialModel" label="备品型号" />
<el-table-column prop="stockCount" label="调拨数量" />
<el-table-column prop="materialUnit" label="备品单位" />
</el-table>
<el-pagination
v-if="selectDataFlag"
:page-sizes="selectDataPageInfo.pageSizes"
:page-size="selectDataPageInfo.size"
:layout="selectDataPageInfo.layout"
:total="selectDataPageInfo.total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
//存放选中数据
selectedEndAllData: [],
allData:[]
//分页器
selectDataPageInfo: {
total: 0,
pageSizes: [10, 20, 30],
layout: 'total, prev, pager, next',
page: 0,//第几页
size: 10
},
//获取数据
getTableData() {
if (this.selectDataPageInfo.page in this.allData) return
this.selectTableLoading = true
const tempObj = {
page: this.selectDataPageInfo.page,
size: this.selectDataPageInfo.size,
...this.selectInfo
}
crudMaterialOrderAdjust.getMaterialStockByCon(tempObj).then(res => {
this.selectTableLoading = false
this.allData[this.selectDataPageInfo.page] = res.content
const allIds = this.form.children.map(m => m.id)
this.allData[this.selectDataPageInfo.page].forEach(f => {
if (allIds.includes(f.id)) {
this.$refs.selTable.toggleRowSelection(f, true)
}
})
this.selectDataPageInfo.total = res.totalElements
}).catch(err => {
this.selectTableLoading = false
this.$message.error(err.response)
})
},
//弹窗的确认,取消函数
selectDataSure() {
this.selectDataFlag = false
const hash = {}
this.form.children = this.selectedEndAllData.reduce((pre, cur) => {
hash[cur.id] ? '' : hash[cur.id] = true && pre.push(cur)
return pre
}, [])
this.selectedEndAllData = []
},
selectDataCancle() {
this.selectDataFlag = false
this.$refs.selTable.clearSelection()
},
表格高度自适应
主要借助window.onresize来监听浏览器窗口变化
data(){
return {
tableHeight: 0
}
},
created() {
this.tableHeight = window.innerHeight - 250
},
mounted() {
window.onresize = () => {//挂载onresize
this.tableHeight = window.innerHeight - 250
}
},
destroyed() {//销毁
window.onresize = null
},
网友评论