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

@canvas-components/react-pivot-table

v0.2.12

Published

React adapter for the pivot table core engine.

Downloads

1,605

Readme

@canvas-components/react-pivot-table

@canvas-components/react-pivot-table 是 @canvas-components/pivot-table 的 React 适配层,在保留原生 Canvas 数据透视表性能的同时,提供标题栏、字段配置面板、图表联动和 React ref 接口。

示例效果

React Pivot Table 示例

功能作用

  • 提供 ReactPivotTable 组件
  • 支持行、列、指标的多层聚合与虚拟滚动
  • 支持字段面板配置和透视图表联动
  • 暴露选择、展开、筛选、排序、导出和状态快照方法
  • 聚合、布局和 Canvas 渲染复用纯原生 pivot-table 内核

安装方法

pnpm add @canvas-components/react-pivot-table @canvas-components/pivot-table react@^16.8 react-dom@^16.8

最低依赖版本:

  • react >= 16.8.0
  • react-dom >= 16.8.0
  • Node.js >= 18.12.0
  • pnpm >= 9.0.0

使用方法

import { ReactPivotTable } from "@canvas-components/react-pivot-table";

interface SalesRecord {
  region: string;
  city: string;
  year: number;
  sales: number;
}

export function SalesPivotTable(props: { data: SalesRecord[] }) {
  return (
    <div style={{ width: "100%", height: 560 }}>
      <ReactPivotTable<SalesRecord>
        title="销售数据透视表"
        dataSource={props.data}
        rows={[
          { key: "region", title: "区域", dataIndex: "region" },
          { key: "city", title: "城市", dataIndex: "city" },
        ]}
        columns={[{ key: "year", title: "年份", dataIndex: "year" }]}
        indicators={[
          {
            key: "sales",
            title: "销售额",
            dataIndex: "sales",
            aggregator: "sum",
          },
        ]}
        totals={{
          showRowSubtotals: true,
          showColumnGrandTotal: true,
          showRowGrandTotal: true,
        }}
      />
    </div>
  );
}

属性说明

ReactPivotTableProps

ReactPivotTableProps 继承自 PivotTableOptions,并增加 React 宿主相关属性。

| 属性 | 类型 | 说明 | | --------------- | ------------------------------------------------ | ---------------------------- | | className | string | 根节点类名 | | style | CSSProperties | 根节点样式 | | title | ReactNode | 标题栏内容 | | customization | boolean \| ReactPivotTableCustomizationOptions | 是否启用字段配置面板及其配置 |

其余 dataSource、rows、columns、indicators、totals、filters、sorts 和虚拟滚动等属性与 @canvas-components/pivot-table 保持一致。

统一切换调试模式

ReactPivotTableDebugProvider 可为后代中的全部 ReactPivotTable 同步开启核心调试模式,并保留每个表格自身的 debug 配置:

import {
  ReactPivotTable,
  ReactPivotTableDebugProvider,
} from "@canvas-components/react-pivot-table";

<ReactPivotTableDebugProvider enabled={debuggerEnabled}>
  <ReactPivotTable
    {...props}
    debug={{ showBodyBounds: false, logDrawCalls: true }}
  />
</ReactPivotTableDebugProvider>;

ReactPivotTableCustomizationOptions

| 属性 | 类型 | 说明 | | ---------------- | ------------------ | ------------------------ | | fields | PivotField[] | 可参与透视配置的全部字段 | | open | boolean | 受控字段面板开关 | | defaultOpen | boolean | 非受控字段面板初始状态 | | layout | PivotFieldLayout | 受控字段区域布局 | | defaultLayout | PivotFieldLayout | 非受控字段区域初始布局 | | panelWidth | number | 字段面板宽度 | | onOpenChange | (open) => void | 面板开关变化回调 | | onLayoutChange | (layout) => void | 字段区域布局变化回调 | | onFieldChange | (field) => void | 字段配置变化回调 |

实例方法

通过 ReactPivotTableRef 可以访问以下能力:

  • 获取透视模型、可见行列节点和单元格明细记录
  • 读取或设置选择状态,并滚动到指定单元格
  • 展开、收起行列节点或全部节点
  • 设置维度筛选、维度排序和指标排序
  • 导出 CSV、XLSX
  • 获取和恢复版本化状态快照
  • 获取调试快照

推荐场景

  • React 数据分析后台
  • 大数据量多维聚合报表
  • 需要字段拖放配置或图表联动的数据透视场景
  • 需要原生 Canvas 性能和 React 组件用法的场景