antd vue表格使用

1、表格整行添加点击事件
方法一:在data中设置对应得点击事件

 <a-table
	:loading="loading"
	:columns="columns"
	:dataSource="tableData"
	:pagination="false"
	:rowSelection="rowSelection"
	:customRow="rowClick"
/>
<script>
	export default {
		data(){
			return {
				 rowClick: record => ({
                    on: { // 事件
                        click: () => {
                            // 点击改行时要做的事情
                            console.log('record', record)
                        },
                    }
                })
			}
		}
	}
</script>

方法二:在methods中设置

<script>
	export default {
		methods:{
			rowClick(record, index){
                return {
                    on: {
                        click: () => {
                            console.log(record,index)
                        }
                    }
                }
            }
		}
	}
</script>

2、设置点击该行选中多选框,已选则取消多选

<template>
	<a-table
		:loading="loading"
		:columns="columns"
		:dataSource="tableData"
		:pagination="false"
		:rowSelection="rowSelection"
		:rowClassName="setRowClassName"
		:customRow="rowClick"
		:rowKey="rowKey"
	/>
</template>

<script>
	export default {
		data(){
			return {
        		selectedRowKeys: [],
				options: {
                    selectedRowKeys: this.selectedRowKeys,
                    onChange: this.onSelectChange
                },
			}
		},
		 computed: {
            rowSelection() {
                return this.options
            }
        },
        methods:{
        	onSelectChange(selectedRowKeys, selectedRows) {
                this.options = {
                    selectedRowKeys: selectedRowKeys,
                    onChange: this.onSelectChange
                }
            }
        }
	}
</script>

1.antd表格设置:https://blog.csdn.net/weixin_44051815/article/details/90049091
2.单选高亮设置:https://blog.csdn.net/zm_miner/article/details/83026968
3.多选框点击行设置:https://blog.csdn.net/qq_35331167/article/details/90174428

3、利用slot方法自定义单元格显示内容
单个

<template>
  <a-table :columns="columns" :dataSource="data">
    <a slot="action" slot-scope="text" href="javascript:;">Delete</a>
  </a-table>
</template>
<script>
const columns = [
    { title: 'Name', dataIndex: 'name', key: 'name' },
    { title: 'Age', dataIndex: 'age', key: 'age' },
    { title: 'Address', dataIndex: 'address', key: 'address' },
    { title: 'Action', dataIndex: '', key: 'x', scopedSlots: { customRender: 'action' } },
  ];
</script>

多个

<template>
  <a-table :columns="columns" :dataSource="data">
    <template v-for="col in ['name','age','address']" :slot="col" slot-scope="text,record">
    	<div :key='col'></div>
    </template>
  </a-table>
</template>
<script>
const columns = [
    { title: 'Name', dataIndex: 'name', key: 'name' , scopedSlots: { customRender: 'name' } },
    { title: 'Age', dataIndex: 'age', key: 'age' , scopedSlots: { customRender: 'age' } },
    { title: 'Address', dataIndex: 'address', key: 'address', scopedSlots: { customRender: 'address' } },
  ];
</script>

4、使用render方法自定义单元格显示内容

const columns = [
	               {
                    title: '操作',
                    dataIndex: 'operation',
                    fixed: 'right',
                    align: 'center',
                    customRender: (text, record) => {
                        const h = this.$createElement
                        let ele = [
                            h('a-menu-item', {key: 1,}, '重新分配账号'),
                            h('a-menu-item', {key: 2}, '手动同步主数据'),
                            h('a-menu-item', {key: 3}, '重置密码')
                        ]
                        return h('a-dropdown', {
                            props: {
                                placement: 'bottomCenter'
                            }
                        }, [
                            h('a-menu', {
                                slot: 'overlay',
                                on: {
                                    'click': (e) => {
                                        this.handleMenuClick(e.key, record)
                                    }
                                }
                            }, ele),
                            h('a-button', ['操作', h('a-icon', {props: {type: 'down'}})])
                        ])
                    }
                }
            ]
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,可以得知该问题是关于如何使用Antd Vue组件库中的动态表格scroll的。下面是一个简单的例子,演示如何使用Antd VueTable组件实现动态表格scroll: ```vue template> <a-table :columns="columns" :data-source="dataList" :scroll="{ x: '100%', y: `calc(100vh - ${tableTop+280+'px'})` }" :pagination="false"> <template slot="title"> <div class="table-title">Table Title</div> </template> </a-table> </template> <script> export default { data() { return { columns: [ { title: 'Name', dataIndex: 'name', key: 'name', }, { title: 'Age', dataIndex: 'age', key: 'age', }, { title: 'Address', dataIndex: 'address', key: 'address', }, ], dataList: [ { key: '1', name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', }, { key: '2', name: 'Jim Green', age: 42, address: 'London No. 1 Lake Park', }, { key: '3', name: 'Joe Black', age: 32, address: 'Sidney No. 1 Lake Park', }, // ... more data ], tableTop: 0, tableList: [], }; }, mounted() { const a = document.querySelector('.ant-table-header'); this.tableList = [a.clientHeight, a.clientHeight]; this.tableTop = this.tableList[0]; }, watch: { columns() { setTimeout(() => { const a = document.querySelector('.ant-table-header'); this.tableList.push(a.clientHeight); this.tableList.splice(0, 1); this.tableTop = this.tableList[1]; }, 10); }, }, }; </script> ``` 在上面的代码中,我们使用Antd VueTable组件,并设置了columns和dataList属性来定义表格的列和数据。我们还设置了scroll属性来控制表格的滚动,其中x属性设置为'100%',表示表格宽度自适应,y属性设置为`calc(100vh - ${tableTop+280+'px'})`,表示表格高度自适应。我们还使用了mounted和watch属性来动态计算表头高度和更新表格高度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值