mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-24 12:45:18 +08:00
67 lines
1.1 KiB
Markdown
67 lines
1.1 KiB
Markdown
# Selection
|
|
|
|
Rows can be selectable by making first column's type as `selection`.
|
|
|
|
```html
|
|
<div>You have selected {{ checkedRowKeys.length }} row{{ checkedRowKeys.length < 2 ? '': 's'}}.</div>
|
|
|
|
<n-data-table
|
|
ref="table"
|
|
:columns="columns"
|
|
:data="data"
|
|
:pagination="pagination"
|
|
:row-key="row => row.address"
|
|
@update:checked-row-keys="handleCheck"
|
|
/>
|
|
```
|
|
|
|
```js
|
|
const columns = [
|
|
{
|
|
type: 'selection',
|
|
disabled (row, index) {
|
|
return row.name === 'Edward King 3'
|
|
}
|
|
},
|
|
{
|
|
title: 'Name',
|
|
key: 'name'
|
|
},
|
|
{
|
|
title: 'Age',
|
|
key: 'age'
|
|
},
|
|
{
|
|
title: 'Address',
|
|
key: 'address'
|
|
}
|
|
]
|
|
|
|
const data = Array.apply(null, { length: 46 }).map((_, index) => ({
|
|
name: `Edward King ${index}`,
|
|
age: 32,
|
|
address: `London, Park Lane no. ${index}`
|
|
}))
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
data,
|
|
columns,
|
|
checkedRowKeys: [],
|
|
pagination: {
|
|
pageSize: 5
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
sendMail(rowData) {
|
|
this.$NMessage.info('send mail to ' + rowData.name)
|
|
},
|
|
handleCheck (rowKeys) {
|
|
this.checkedRowKeys = rowKeys
|
|
}
|
|
}
|
|
}
|
|
```
|