2018-04-03 14:18:18 +00:00
|
|
|
<cn>
|
|
|
|
#### 选择和操作
|
|
|
|
选择后进行操作,完成后清空选择,通过 `rowSelection.selectedRowKeys` 来控制选中项。
|
|
|
|
</cn>
|
|
|
|
|
|
|
|
<us>
|
|
|
|
#### Selection and operation
|
|
|
|
To perform operations and clear selections after selecting some rows, use `rowSelection.selectedRowKeys` to control selected rows.
|
|
|
|
</us>
|
|
|
|
|
2019-10-09 10:32:23 +00:00
|
|
|
```tpl
|
2018-04-03 14:18:18 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div style="margin-bottom: 16px">
|
2019-09-28 12:45:07 +00:00
|
|
|
<a-button type="primary" @click="start" :disabled="!hasSelected" :loading="loading">
|
2018-04-03 14:18:18 +00:00
|
|
|
Reload
|
|
|
|
</a-button>
|
|
|
|
<span style="margin-left: 8px">
|
|
|
|
<template v-if="hasSelected">
|
|
|
|
{{`Selected ${selectedRowKeys.length} items`}}
|
|
|
|
</template>
|
|
|
|
</span>
|
|
|
|
</div>
|
2019-09-28 12:45:07 +00:00
|
|
|
<a-table
|
|
|
|
:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
|
|
|
|
:columns="columns"
|
|
|
|
:dataSource="data"
|
|
|
|
/>
|
2018-04-03 14:18:18 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2019-09-28 12:45:07 +00:00
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: 'Name',
|
|
|
|
dataIndex: 'name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Age',
|
|
|
|
dataIndex: 'age',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Address',
|
|
|
|
dataIndex: 'address',
|
|
|
|
},
|
|
|
|
];
|
2018-04-03 14:18:18 +00:00
|
|
|
|
2019-09-28 12:45:07 +00:00
|
|
|
const data = [];
|
|
|
|
for (let i = 0; i < 46; i++) {
|
|
|
|
data.push({
|
|
|
|
key: i,
|
|
|
|
name: `Edward King ${i}`,
|
|
|
|
age: 32,
|
|
|
|
address: `London, Park Lane no. ${i}`,
|
|
|
|
});
|
|
|
|
}
|
2018-04-03 14:18:18 +00:00
|
|
|
|
2019-09-28 12:45:07 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
data,
|
|
|
|
columns,
|
|
|
|
selectedRowKeys: [], // Check here to configure the default column
|
|
|
|
loading: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
hasSelected() {
|
|
|
|
return this.selectedRowKeys.length > 0;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
start() {
|
|
|
|
this.loading = true;
|
|
|
|
// ajax request after empty completing
|
|
|
|
setTimeout(() => {
|
|
|
|
this.loading = false;
|
|
|
|
this.selectedRowKeys = [];
|
|
|
|
}, 1000);
|
|
|
|
},
|
|
|
|
onSelectChange(selectedRowKeys) {
|
|
|
|
console.log('selectedRowKeys changed: ', selectedRowKeys);
|
|
|
|
this.selectedRowKeys = selectedRowKeys;
|
|
|
|
},
|
2018-04-03 14:18:18 +00:00
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
};
|
2018-04-03 14:18:18 +00:00
|
|
|
</script>
|
|
|
|
```
|