You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

a-virtual-table

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-virtual-table

The virtual scrolling component developed based on the Table component of Ant Design supports dynamic height and solves the problem of scrolling stuck when the amount of data is large.

Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
3
-57.14%
Maintainers
1
Weekly downloads
 
Created
Source

a-virtual-table

基于Ant-Design-Vue的 Table 组件开发的虚拟滚动组件,支持动态高度,解决数据量大时滚动卡顿的问题。

⚠️仅支持vue2、Ant-Design-Vue@1。

demo & 源码:https://xiaocheng555.github.io/a-virtual-table/

安装

# for npm:
$ npm i a-virtual-table -S
# for yarn:
$ yarn add a-virtual-table -S

用法

<template>
  <div>
    <a-virtual-table
      :columns="columns"
      :data-source="list"
      :itemSize="54"
      keyProp="id"
      row-key="id"
      :pagination="false"
      :scroll="{ x: 1300, y: 800 }">
      <a slot="name" slot-scope="{text}">{{ text }}===</a>
    </a-virtual-table>
  </div>
</template>

<script>
import { mockData } from '@/utils'
import AVirtualTable from '../a-virtual-table'

export default {
  components: {
    AVirtualTable
  },
  data () {
    return {
      columns: [
        {
          title: 'Name',
          dataIndex: 'name',
          key: 'name',
          scopedSlots: { customRender: 'name' },
          fixed: 'left',
          width: 200
        },
        {
          title: 'id',
          dataIndex: 'id',
          key: 'id',
          width: 100
        },
        {
          title: 'text',
          dataIndex: 'text',
          key: 'text',
          width: 400
        },
        {
          title: 'Address',
          dataIndex: 'address',
          key: 'address 1',
          ellipsis: true,
          width: 400
        },
        {
          title: 'Long Column Long Column Long Column',
          dataIndex: 'address',
          key: 'address 2',
          ellipsis: true,
          width: 300
        },
        {
          title: 'Long Column Long Column',
          dataIndex: 'address',
          key: 'address 3',
          ellipsis: true,
          width: 300
        },
        {
          title: 'Long Column',
          dataIndex: 'address',
          key: 'address 4',
          ellipsis: true,
          width: 300,
          fixed: 'right',
        }
      ],
      list: mockData(0, 2000)
    }
  }
}
</script>

a-virtual-table 组件

Props

参数说明类型可选值默认值
dataSource总数据Array必填
keyPropkey值,data数据中的唯一id【⚠️若keyProp未设置或keyProp值不唯一,可能导致表格空数据或者滚动时渲染的数据断层、不连贯】stringid
itemSize每一行的预估高度number60
scrollBox指定滚动容器;在指定滚动容器时,如果表格设置了height高度,则滚动容器为表格内的滚动容器;如果表格为设置height高度,则自动获取父层以外的滚动容器,直至window容器为止string-
buffer顶部和底部缓冲区域,值越大显示表格的行数越多Number200
throttleTime滚动事件的节流时间number10
dynamic动态获取表格行高度,默认开启。设置为false时,则以itemSize为表格行的真实高度,能大大减少虚拟滚动计算量,减少滚动白屏;如果itemSize与表格行的真实高度不一致,可能导致滚动时表格数据错乱booleantrue
virtualized是否开启虚拟滚动booleantrue
*支持 <a-table> 组件的props属性,更多请看 <a-table> api--

Methods

方法名说明参数
scrollTo滚动到第几行【不太精确:因为滚动到第n行时,如果周围的表格行计算出真实高度后会更新高度,导致当前行坍塌或撑起】index
update更新-
clearSelection用于多选 <virtual-column type="selection">,清空用户的选择-
toggleRowSelection用于多选 <virtual-column type="selection">, 切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中)row, selected

Events

事件名称说明参数
change计算完成真实显示的表格行数(renderData, start, end):renderData 真实渲染的数据,start和end指的是渲染的数据在总数据的开始到结束的区间范围
selection-change虚拟表格多选选项发生更改时触发事件selectedRows

更新内容

2023-1-13

  • 修复滚动容器设置为window时报错

  • 修复指定滚动容器,偶现滚动时表头会一直在

Keywords

vue

FAQs

Package last updated on 13 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts