<a-table
:row-selection="rowSelection"
:scrollToFirstRowOnChange="true"
class="ant-table-striped"
sticky
:row-class-name="(_record: Record<string, any>, index: number) => (index % 2 === 1 ? 'table-striped' : null)"
:dataSource="dataSource"
:columns="columns"
:pagination="pagination"
:loading="loading"
rowKey="id"
:scroll="scroll"
@change="handleTableChange"
></a-table>
const selectedApiRowKeys: Ref<string[]> = ref([]);
const rowSelection: TableProps['rowSelection'] = {
selectedRowKeys: selectedApiRowKeys.value,
onSelect: (record: Record<string, any>, selected, _selectedRows, _nativeEvent) => {
if (selected) selectedApiRowKeys.value.push(record.id);
if (!selected)
selectedApiRowKeys.value.splice(
0,
selectedApiRowKeys.value.length,
...selectedApiRowKeys.value.filter(item => item !== record.id),
);
},
onSelectAll: (selected, selectedRows, changeRows) => {
if (selected) {
selectedApiRowKeys.value.splice(
0,
selectedApiRowKeys.value.length,
..._.union(
selectedApiRowKeys.value,
selectedRows.map(item => item.id),
),
);
}
if (!selected) {
selectedApiRowKeys.value.splice(
0,
selectedApiRowKeys.value.length,
...selectedApiRowKeys.value.filter(item => !changeRows.map(item => item.id).includes(item)),
);
}
},
getCheckboxProps: (_record: DataType) => ({
// disabled: record.name === 'Disabled User', // Column configuration not to be checked
// name: record.name,
}),
};```
vue3+antdv+table选择
最新推荐文章于 2025-01-10 09:51:31 发布