-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
能不能在el-table上增加一个指令,根据剩余空间,自动设置最大高度,这样表格不会超出整个页面,滚动条只会出现在表格内部 #1662
Comments
lxy545480918
changed the title
能不能在el-table上增加一个指令,使其数据量多的时候,只在appmain里面滚动,而不是整个页面
能不能在el-table上增加一个指令,根据剩余空间,自动设置最大高度,这样表格不会超出整个页面,滚动条只会出现在表格内部
Mar 5, 2019
这应该给 |
@PanJiaChen 大神,element-ui的效率没你高啊,这个指令可以更加好一点 |
刚好写了一个,应该能满足你的要求 /**
* 表格高度自适应,使用此功能必须先为表格设置初始值
*/
Vue.directive('table-height-adaptive', {
/**
*
* @param {*} el
* @param {*} binding
* binding.value 格式为 {
* table: $refs.table, // 表格对象
* topHeight: 140 // 表格顶边 距离顶部高度,默认值为 140
* footerHeight: 120 // 表格底部 距离底部高度,默认值为 120
* }
* @param {*} vnode
* @param {*} oldVnode
*/
update(el, binding, vnode, oldVnode) {
let topHeight = binding.value.topHeight ? binding.value.topHeight : 140
let footerHeight = binding.value.footerHeight ? binding.value.footerHeight : 120
let table = binding.value.table
let tableHeight = window.innerHeight - el.offsetTop - footerHeight - topHeight;
table.layout.setHeight(tableHeight)
table.doLayout()
// 监听窗口大小变化
window.addEventListener("resize", () => {
tableHeight = window.innerHeight - el.offsetTop - footerHeight - topHeight
table.layout.setHeight(tableHeight)
table.doLayout()
})
}
}) 用法如下: <el-table ..... **ref="table" height="50" v-table-height-adaptive="{table: $refs.table}" |
@yuntao1997 欢迎pr |
@PanJiaChen 已提交 pr demo预览:http://jsrun.net/a3XKp/edit |
@yuntao1997 流弊 |
@yuntao1997 大神orz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: