Skip to content

GridTable

类型table组件,不同的是布局使用grid而不是table

示例



点我查看代码
tsx
import { GridTable } from "@wenonly/react-components";
import { Card } from "antd";
import React from "react";
import { useMemo, useState } from "react";

const data = Array(100)
  .fill(1)
  .map((_, index) => ({
    id: index,
    name: `姓名${index}`,
    age: index,
  }));

const RCGridTable: React.FunctionComponent = () => {
  const [pageSize, setPageSize] = useState(6);
  const [page, setPage] = useState(1);

  const dataSource = useMemo(() => {
    return data.slice((page - 1) * pageSize, (page - 1) * pageSize + pageSize);
  }, [page]);

  return (
    <GridTable
      rowKey="id"
      gridGap={20}
      dataSource={dataSource}
      pagination={{
        pageSize: pageSize,
        current: page,
        total: data.length,
        onChange(page, pageSize) {
          setPage(page);
          setPageSize(pageSize);
        },
      }}
    >
      {(r) => (
        <Card title={r.name}>
          <div>姓名:{r.name}</div>
          <div>年龄:{r.age}</div>
        </Card>
      )}
    </GridTable>
  );
};

export default RCGridTable;

参数

key类型描述
loadingboolean | undefined是否加载中
dataSourceRecordType[] | undefined数据源
gridGapnumber | undefined网格间距
gridItemMinWidthnumber | undefined网格最小宽度
paginationfalse | PaginationProps | undefined分页
cardStyleReact.CSSProperties | undefined卡片样式
styleReact.CSSProperties | undefined样式
rowKeystring | undefined唯一标识
children((r: RecordType) => React.ReactNode) | undefined子组件