Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBTable配置成Tree Table自动展开属性不起作用。 #40

Closed
whyuan1976 opened this issue Jun 21, 2017 · 10 comments
Closed

DBTable配置成Tree Table自动展开属性不起作用。 #40

whyuan1976 opened this issue Jun 21, 2017 · 10 comments

Comments

@whyuan1976
Copy link

whyuan1976 commented Jun 21, 2017

defaultExpandAllRows 不起作用。手工可以点开。试了一下,底层应该是可以的。

类似如下:
https://codepen.io/anon/pen/OgmVmR?editors=001

@jiangxy
Copy link
Owner

jiangxy commented Jun 23, 2017

我试了下貌似是可以,直接改的InnerTable.js,代码类似这样:

<Table rowSelection={rowSelection} columns={this.tableSchema} dataSource={this.state.data} pagination={false}
               loading={tableLoading} expandedRowRender={record => <p>{'test'}</p>}
               defaultExpandedRowKeys={[1000, 1001]}/>

效果是这样:
image

是不是defaultExpandAllRows的数据类型不对?如果写成['1000', '1001']是不会生效的

@whyuan1976
Copy link
Author

whyuan1976 commented Jun 24, 2017

谢谢楼主回答。我这边有2种场景,
1: 树形结构的数据(如组织关系的table),是通过data的children来维护结构的,这种模式需要默认展开所有的数据。问题反应的就是这种场景,还没有试过defaultExpandedRowKeys,不过就算可以,也十分不方便。
2:自定义展开,就是楼主的方式。我这里已经扩展了这部分功能,可以自定义展开内容(如table),不过精力有限,扩展的自定义组件的方式,非配置。这种方式默认不展开明细,展开按下,再加载远程数据。

image

@whyuan1976
Copy link
Author

whyuan1976 commented Jun 25, 2017 via email

@ywzhaiqi
Copy link

ywzhaiqi commented Jul 3, 2017

传递给 table 的 dataSource 的数据是筛选过的(结构如下),默认没有了 children

{
  $$rawData: {},
  id: 1,
  title: 'aaa'
}

可修改 InnerTable.js 文件

transformRawDataToTable(obj) {
  const newObj = {};

  // 这段代码真是好蛋疼...
  for (const key in obj) {
    // added to Support children
    if (key === 'children') {
      // add key
      obj.children.forEach(a => {
        a.key = a.id;
      });
      newObj[key] = obj[key];
      continue;
    }

    if (!this.fieldMap.get(key))
      continue;

@ywzhaiqi
Copy link

ywzhaiqi commented Jul 3, 2017

@whyuan1976

这种方式默认不展开明细,展开按下,再加载远程数据。

你怎么加载远程数据的?expandedRowRender 不是只能是个函数吗?

@whyuan1976
Copy link
Author

@ywzhaiqi

树形结构的table(例如组织关系)是不需要2次加载的,这时希望能使用defaultExpandAllRows 全展开。按照指定key的方式,是可以展开的,就是太麻烦了。二次加载的table也做过,加载的数据需要按照展开的key做map保存。我偷懒展开一个就自动关闭其他的,只需要保存最新展开的data。

@ywzhaiqi
Copy link

ywzhaiqi commented Jul 3, 2017

@whyuan1976
没懂,二次加载是在 expandedRowRender 函数里面的吗?这不是组件,没法设置 ajax 的返回值。

@whyuan1976
Copy link
Author

二次加载是在onExpand里实现,二次加载这部分没问题。是一次性加载树形结构的数据,无法通过defaultExpandAllRows 属性默认展开所有节点。

@ywzhaiqi
Copy link

ywzhaiqi commented Jul 3, 2017

@whyuan1976

原来是 onExpand,谢谢。

你的这个问题是 antd table 自身的问题。你的示例改成 componentDidMount 加载数据,默认就不会展开了。
https://codepen.io/ywzhaiqi/pen/YQLNva

@whyuan1976
Copy link
Author

@ywzhaiqi
谢谢。好像是的,改成componentWillMount就没有问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants