现有需求, 使用element-ui中el-table进行开发一个分组业务组件, 可以新增分组, 分组展示列表的最大高度160, 列表数量超过4条则显示滚动条
添加分组功能, 点击新建分组, table的列表数据新增一条, 列表数量过多, 无法显示;
期望: 列表数量过多, 点击新增, 自动滚动到新增那条数据所在的位置
业务代码
//添加分组
addGroupItem() {
const newRow = {
groupName: '',
show: true,
protocolId: this.protocolId
}
this.groupList.push(newRow)
this.addDisabled = true
//设置该条新增数据为选中行
this.$refs['groupInst'][0].setCurrentRow(newRow)
this.$nextTick(() => {
// instance为el-table组件的使用, 内部返回的是其ref的实例对象
const instance = this.$refs['groupInst'][0].getTableInst()
instance.bodyWrapper.scrollTop = instance.bodyWrapper.scrollHeight;
})
},
参考文章:
https://blog.csdn.net/Dream_xun/article/details/85101125?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.nonecase