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

[<t-table>] expanded展开行能不能控制一键全关闭以及同时只能展开一个? #2607

Closed
156786462 opened this issue Jul 23, 2023 · 2 comments
Labels
question Further information is requested

Comments

@156786462
Copy link

156786462 commented Jul 23, 2023

tdesign-vue 版本

^1.3.0

重现链接

No response

重现步骤

No response

期望结果

No response

实际结果

No response

框架版本

No response

浏览器版本

No response

系统版本

No response

Node版本

No response

补充说明

No response

Tasks

No tasks being tracked yet.
@github-actions
Copy link
Contributor

👋 @156786462,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@chaishi
Copy link
Collaborator

chaishi commented Jul 24, 2023

一键打开和关闭(重点在 onExpandChange 中的逻辑)

<template>
  <div>
    <t-table :data="tableData" :expandedRowKeys="expandedRowKeys" :onExpandChange="onExpandChange" />
    <t-button @click="onToggleExpanded">打开全部/关闭全部</t-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [{ id: '123', name: 'user name' }],
      expandedRowKeys: [],
    }
  },

  methods: {
    onToggleExpanded() {
      this.expandedRowKeys = this.expandedRowKeys.length ? [] : this.tableData.map(item => item.id);
    },
  }
}
</script>

控制同时只能打开一个(重点在 onExpandChange 中的逻辑)

<template>
  <t-table :data="tableData" :expandedRowKeys="expandedRowKeys" :onExpandChange="onExpandChange" />
</template>

<script>
export default {
  data() {
    return {
      tableData: [{ id: '123', name: 'user name' }],
      expandedRowKeys: [],
    }
  },

  methods: {
    // 保持 this.expandedRowKeys 始终只有一个值,就可以保证同时只能打开一个。同理可推,可以保持可以同时打开任意个数。
    onExpandChange(val, { expandedRowData }) {
      this.expandedRowKeys = val.length ?  [expandedRowData.id] : [];
      // 或者
      // this.expandedRowKeys = this.expandedRowKeys.length ? [] : val;
    },
  }
}
</script>

@chaishi chaishi added the question Further information is requested label Jul 24, 2023
@chaishi chaishi closed this as completed Jul 24, 2023
@chaishi chaishi changed the title [<t-table>] expanded展开行不能控制一键全关闭以及同时只能展开一个。 [<t-table>] expanded展开行能不能控制一键全关闭以及同时只能展开一个? Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants