Only study only, for the virtual scroll design,please refer the wiki, Vue - Table表格渲染上千数据优化
Table enhancement with the thousands of data rendering: add common table body with Reflow, requestAnimationFrame and virtual scroll enhancement
source-shell
# install dependencies
npm install
# serve with hot reload at localhost:7777
npm run dev
# build for production with minification
npm run build
columnsConfig
: require property, Each column configdata
: table data.filters(TBC)
: to filter table data.renderType
(default: common
): display table body render type,VIRTUAL -> virtual scroll body; ANIMATION -> use window.requestAnimationFrame to render body with frame scroll.recordKey
: require property to optimize the table body to reuse the DOM elements.height
(default: 400
): display height of the table in integer number, including header and body.headerHeight
(default: 40
): display height of the header in integer number.recordHeight
(default: 36
): display height of the items in integer number.For virtual body scroll render,it used to calculate the scroll height and position.title
: 列头显示文字key
: 对应列内容的字段名render
: 自定义渲染列,使用 Vue 的 Render 函数通过初始配置 constant.js
再用上图计算获取Table显示最小高度 Math.floor(scrollTop-remain / itemHeight) * itemHeight
与最大高度 Math.ceil((scrollTop+viewPort+remain) / itemHeight) * itemHeight
使用最小高度与最大高度得到最小索引值与最大索引值区间并同时可以计算出每行数据位置 translateY: index * itemHeight
最后是通过Scroll事件动态更新scrollTop同时使用lodash的 findIndex()
减去/添加数据从而实现上下拉滚动更新数据
#vuejs #javascript #vue-js #vue