mirror of
https://github.com/element-plus/element-plus.git
synced 2025-08-14 10:00:58 +08:00

* perf: change to import-x * feat: add rules * chore: fix rule * chore: fix * chore: fix * chore: fix * style: `pnpm lint:fix` * Revert "style: `pnpm lint:fix`" This reverts commit db0116a288299c507e3cfc4d7a22e2207265d920. * Revert "chore: fix" This reverts commit 69c82a90c01525e38180be4c21e8ef5602512318. * chore: fix * style: `pnpm lint:fix` * fix: lint * chore: `pnpm format`
105 lines
2.4 KiB
Vue
105 lines
2.4 KiB
Vue
<template>
|
|
<el-table
|
|
ref="multipleTableRef"
|
|
:data="tableData"
|
|
row-key="id"
|
|
style="width: 100%"
|
|
@selection-change="handleSelectionChange"
|
|
>
|
|
<el-table-column type="selection" :selectable="selectable" width="55" />
|
|
<el-table-column label="Date" width="120">
|
|
<template #default="scope">{{ scope.row.date }}</template>
|
|
</el-table-column>
|
|
<el-table-column property="name" label="Name" width="120" />
|
|
<el-table-column property="address" label="Address" />
|
|
</el-table>
|
|
<div style="margin-top: 20px">
|
|
<el-button @click="toggleSelection([tableData[1], tableData[2]])">
|
|
Toggle selection status of second and third rows
|
|
</el-button>
|
|
<el-button @click="toggleSelection([tableData[1], tableData[2]], false)">
|
|
Toggle selection status based on selectable
|
|
</el-button>
|
|
<el-button @click="toggleSelection()">Clear selection</el-button>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref } from 'vue'
|
|
|
|
import type { TableInstance } from 'element-plus'
|
|
|
|
interface User {
|
|
id: number
|
|
date: string
|
|
name: string
|
|
address: string
|
|
}
|
|
|
|
const multipleTableRef = ref<TableInstance>()
|
|
const multipleSelection = ref<User[]>([])
|
|
|
|
const selectable = (row: User) => ![1, 2].includes(row.id)
|
|
const toggleSelection = (rows?: User[], ignoreSelectable?: boolean) => {
|
|
if (rows) {
|
|
rows.forEach((row) => {
|
|
multipleTableRef.value!.toggleRowSelection(
|
|
row,
|
|
undefined,
|
|
ignoreSelectable
|
|
)
|
|
})
|
|
} else {
|
|
multipleTableRef.value!.clearSelection()
|
|
}
|
|
}
|
|
const handleSelectionChange = (val: User[]) => {
|
|
multipleSelection.value = val
|
|
}
|
|
|
|
const tableData: User[] = [
|
|
{
|
|
id: 1,
|
|
date: '2016-05-03',
|
|
name: 'Tom',
|
|
address: 'No. 189, Grove St, Los Angeles',
|
|
},
|
|
{
|
|
id: 2,
|
|
date: '2016-05-02',
|
|
name: 'Tom',
|
|
address: 'No. 189, Grove St, Los Angeles',
|
|
},
|
|
{
|
|
id: 3,
|
|
date: '2016-05-04',
|
|
name: 'Tom',
|
|
address: 'No. 189, Grove St, Los Angeles',
|
|
},
|
|
{
|
|
id: 4,
|
|
date: '2016-05-01',
|
|
name: 'Tom',
|
|
address: 'No. 189, Grove St, Los Angeles',
|
|
},
|
|
{
|
|
id: 5,
|
|
date: '2016-05-08',
|
|
name: 'Tom',
|
|
address: 'No. 189, Grove St, Los Angeles',
|
|
},
|
|
{
|
|
id: 6,
|
|
date: '2016-05-06',
|
|
name: 'Tom',
|
|
address: 'No. 189, Grove St, Los Angeles',
|
|
},
|
|
{
|
|
id: 7,
|
|
date: '2016-05-07',
|
|
name: 'Tom',
|
|
address: 'No. 189, Grove St, Los Angeles',
|
|
},
|
|
]
|
|
</script>
|