Skip to content

🧐[问题] ProTable如何使用dataSource而非request来更新数据? #7230

Open
@namoshizun

Description

@namoshizun

🧐 问题描述

在protable的文档中虽然解释了 dataSource: Table 的数据,protable 推荐使用 request 来加载,个人理解是当前两者都可以用于设置表内数据。然而个人测试下来发现似乎只设置dataSource的话,table初始还是空白的,如下:

import React, { useState } from 'react';
import { EditableProTable } from '@ant-design/pro-table';

interface Item {
  key: string;
  name: string;
  age: number;
  address: string;
}

const originData: Item[] = [];
for (let i = 0; i < 10; i++) {
  originData.push({
    key: i.toString(),
    name: `Edward ${i}`,
    age: 32,
    address: `London Park no. ${i}`,
  });
}

const App: React.FC = () => {
  const [data, setData] = useState(originData);

  const columns = [
    {
      title: 'name',
      dataIndex: 'name',
      width: '25%',
    },
    {
      title: 'age',
      dataIndex: 'age',
      width: '15%',
    },
    {
      title: 'address',
      dataIndex: 'address',
      width: '40%',
    },
  ];

  return (
    <EditableProTable
      size='small'
      bordered
      rowKey='key'
      dataSource={data}
      columns={columns}
    />
  );
};

export default App;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions