npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zhcw/leaferjs-variable-table

v0.1.6

Published

React + LeaferJS high-volume virtual table with variable row heights.

Readme

leaferjs-variable-table

React + Vite + LeaferJS 的高性能可变行高表格组件库。表格主体使用 LeaferJS Canvas 绘制,DOM overlay 负责分页、Tooltip、编辑器、拖拽辅助线和可访问性语义表格,适合 10 万行级别工程清单、监测台账等大数据展示场景。

安装

npm install leaferjs-variable-table leafer-ui react react-dom
import { LeaferTable } from 'leaferjs-variable-table';
import 'leaferjs-variable-table/style.css';

本地运行

npm install
npm run dev

demo 首屏展示 10 万行不同高度工程项目表,包含固定列、多级表头、分页、选择、展开树、排序筛选、编辑、拖拽、列宽调整、合并单元格、Canvas 标签和状态点。

基础示例

const columns = [
  { title: '序号', dataIndex: 'id', width: 72, fixed: 'left', align: 'right' },
  { title: '线路', dataIndex: 'line', width: 96, fixed: 'left' },
  { title: '项目名称', dataIndex: 'projectName', width: 360, ellipsis: false, editable: true },
  { title: '等级', dataIndex: 'level', width: 88, fixed: 'right' }
];

export function Page() {
  return (
    <LeaferTable
      columns={columns}
      dataSource={rows}
      rowKey="id"
      rowHeight={(record, index) => (index % 6 === 0 ? 112 : 52)}
      scroll={{ x: 1600, y: 620 }}
      height={720}
    />
  );
}

JSX Columns

<LeaferTable dataSource={rows} rowKey="id">
  <LeaferTable.ColumnGroup title="基础信息">
    <LeaferTable.Column title="序号" dataIndex="id" width={72} />
    <LeaferTable.Column title="线路" dataIndex="line" width={96} />
  </LeaferTable.ColumnGroup>
  <LeaferTable.Column title="项目名称" dataIndex="projectName" width={360} />
</LeaferTable>

主要能力

  • Canvas 主体渲染:表头、主体、summary、固定列、固定表头区域、横向虚拟列。
  • 大数据:10 万行、可变行高、滚动定位、scrollTo({ index | key | top | left })
  • Ant Design Table 风格 API:columnsdataSourcerowKeyscrollpaginationsummarytitlefooterrowSelectionexpandable
  • 布局:多级表头、隐藏列、响应式列、固定左右列、未设置宽度列自动分配。
  • 交互:行选择、展开/树形、排序、筛选、行/表头/单元格事件、单元格编辑、行拖拽、列拖拽、列宽拖拽和双击自适应。
  • 绘制扩展:render 支持普通 ReactNode 文本化,也支持 Canvas 协议 texttagbadgestatuscustom
  • 合并单元格:表头 colSpan/rowSpan,主体 onCell().colSpan/rowSpan
  • 可访问性:根节点 role="grid",隐藏语义 table 同步当前可读的表头、行、单元格、caption、footer。

关键 API

LeaferTableProps

| 属性 | 说明 | | --- | --- | | columns / children | 列定义或 JSX Column API | | dataSource | 数据数组 | | rowKey | 字符串字段或函数 | | rowHeight | 固定行高或按行返回高度 | | scroll | 横向/纵向滚动配置 | | pagination | DOM 分页器,支持页码、pageSize、位置和 size changer | | rowSelection | checkbox/radio 选择列,支持禁用、固定、全选、回调 | | expandable | 展开行、树形数据、展开列配置 | | editable | DOM input overlay 编辑配置 | | drag | 行拖拽、列拖拽、列宽调整 | | summary | Canvas summary 行 | | theme | Ant Design Table token 和组件自有 token | | onChange | paginate/sort/filter 统一回调 | | onRenderStats | 返回可视行列范围、绘制 cell 数和绘制耗时 |

LeaferTableColumn

常用字段包括 titledataIndexkeywidthminWidthfixedalignellipsishiddenresponsivechildrenrenderonCellonHeaderCellsorterfilterseditable

Canvas render 协议

{
  title: '等级',
  dataIndex: 'level',
  render: (value) => ({
    type: 'tag',
    text: String(value),
    color: value === '一级' ? '#cf1322' : '#0958d9',
    background: value === '一级' ? '#fff1f0' : '#e6f4ff'
  })
}

主题 Token

theme 覆盖 Ant Design Table 常用 token:bodySortBgborderColorcellFontSizecellPaddingInlinefooterBgheaderBgheaderColorheaderSortActiveBgrowHoverBgrowSelectedBgrowSelectedHoverBgselectionColumnWidthstickyScrollBarBgstickyScrollBarBorderRadius 等。

组件自有 token:canvasBackgroundcellRadiuscellGapcolumnGapfixedShadowscrollbarSizetextBaselineOffset

验证

npm run typecheck
npm run test
npm run build
npm run test:e2e
npm run verify

test:e2e 会启动 Vite,并通过本机 Chrome/Edge 无头模式检查 demo DOM、Canvas、ARIA grid、隐藏语义 table 和截图体积。

发布产物

构建后 dist/ 包含:

  • leaferjs-variable-table.js:ESM
  • leaferjs-variable-table.umd.cjs:UMD/CJS
  • index.d.ts:类型声明
  • style.css:样式

package.json 已配置 exportsmainmoduletypesfiles 和 React/LeaferJS peer dependencies。