微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ant Design Vue中Table的选中详解

<template>
    <a-table
        :columns="columns"
        :data-source="data"
        :row-selection="rowSelection"
    />
</template>
<script lang="ts">
import { defineComponent } from 'vue'
const columns = [
    {
        title: 'Name',dataIndex: 'name',key: 'name',},{
        title: 'Age',dataIndex: 'age',key: 'age',width: '12%',{
        title: 'Address',dataIndex: 'address',width: '30%',key: 'address',]

const data = [
    {
        key: 1,name: 'John brown sr.',age: 60,address: 'New York No. 1 Lake Park',{
        key: 2,name: 'Joe Black',age: 32,address: 'Sidney No. 1 Lake Park',]

const rowSelection = {
    // 选中项发生变化时的回调;根据这个函数就可以获取用户勾选的哪一个值
    onChange: (selectedRowKeys: (string | number)[],selectedRows: []) => {
        console.log(
            `选中的值: ${selectedRowKeys}`,'selectedRows: ',selectedRows
        )
    },// 户手动选择/取消选择某列的回调
    onSelect: (record: [],selected: boolean,selectedRows: []) => {
        console.log(
            '  户手动选择/取消选择某列的回调 ',record,selected,// 用户手动选择/取消选择所有列的回调
    onSelectAll: (selected: boolean,selectedRows: [],changeRows: []) => {
        console.log(
            '  用户手动选择/取消选择所有列的回调  ',selectedRows,changeRows
        )
    },}

export default defineComponent({
    setup() {
        return {
            data,columns,rowSelection,}
    },})
</script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐