Skip to content

Table添加rowClick事件 #1366

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

Closed
1 task
cz-framework opened this issue Oct 31, 2019 · 7 comments
Closed
1 task

Table添加rowClick事件 #1366

cz-framework opened this issue Oct 31, 2019 · 7 comments
Labels

Comments

@cz-framework
Copy link

cz-framework commented Oct 31, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

当用户点击整行的时候,可以触发一些东西(例如弹出详情的窗口)

What does the proposed API look like?

事件为:rowClick。
参数为:row(当前行的数据), index(当前行的序号)

<template>
  <a-table
    :columns="columns"
    :dataSource="data"
    @rowClick="handleRowClick"
  >
    ……
  </a-table>
</template>
<script>
export default {
  ……
  methods: {
    handleRowClick (row, index) {
      console.info('当前点击行的数据', row)
      console.info('当前点击行的序号', index)
    }
  }
  ……
}
</script>
@sendya
Copy link
Member

sendya commented Oct 31, 2019

customRow 用法

适用于 customRow customHeaderRow customCell customHeaderCell。遵循Vue jsx语法。

<Table
  customRow={(record) => {
    return {
      props: {
        xxx... //属性
      },
      on: { // 事件
        click: (event) => {},       // 点击行
        doubleclick: (event) => {},
        contextmenu: (event) => {},
        mouseenter: (event) => {},  // 鼠标移入行
        mouseleave: (event) => {}
      },

    };
  )}
  customHeaderRow={(column) => {
    return {
      on: {
        click: () => {},        // 点击表头行
      }
    };
  )}
/>

https://codesandbox.io/s/5k1z1o0zpl

@cz-framework
Copy link
Author

customRow 用法

适用于 customRow customHeaderRow customCell customHeaderCell。遵循Vue jsx语法。

<Table
  customRow={(record) => {
    return {
      props: {
        xxx... //属性
      },
      on: { // 事件
        click: (event) => {},       // 点击行
        doubleclick: (event) => {},
        contextmenu: (event) => {},
        mouseenter: (event) => {},  // 鼠标移入行
        mouseleave: (event) => {}
      },

    };
  )}
  customHeaderRow={(column) => {
    return {
      on: {
        click: () => {},        // 点击表头行
      }
    };
  )}
/>

https://codesandbox.io/s/5k1z1o0zpl

nice

@KrishnaPG
Copy link

Not sure if this is the right way to handle simple clicks, as it will create one function closure for every row. If there are hundreds of rows in the table, then you are essentially creating one custom row function closure for every row - too bad on memory.

While abstracting the functionality into simple modules, such as custom rows is good, one should also take care of how much additional memory and performance overhead one is adding due to that.

@jcomey
Copy link

jcomey commented May 18, 2020

这么基础的一个功能居然没有!!!

@jcomey
Copy link

jcomey commented May 18, 2020

单击行选择本行数据!!!

@incompletude
Copy link

I don't use JSX. Is there a way to achieve this without it?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants