完整的sample.
使用内置函数 getSelection()
完整代码:
<template>
<j-editable-table
:ref="refKeys[0]"
:loading="OrderItemTable.loading"
:columns="OrderItemTable.columns"
:dataSource="OrderItemTable.dataSource"
:maxHeight="500"
:disabled="formDisabled"
:rowSelection="true"
:row-number="true"
/>
<!-- 添加一个按钮或其他触发事件的方式 -->
<button @click="handleGetSelectedRows">获取选中行</button>
</template>
<script>
export default {
methods: {
handleGetSelectedRows() {
// 获取表格组件的实例
const table = this.$refs[this.refKeys[0]];
// 调用 getSelection 方法获取选中行数据
if (table && typeof table.getSelection === 'function') {
const selectedRows = table.getSelection();
console.log('Selected rows:', selectedRows);
// 在这里可以进一步处理选中行的数据
} else {
console.error('getTableInstance 或 getSelection 方法未定义或不可用');
}
},
},
};
</script>