ant-design-vue/components/vc-table/demo/dropdown.js

107 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-03-26 11:05:40 +00:00
/* eslint-disable no-console,func-names,react/no-multi-comp */
2019-01-12 03:33:27 +00:00
import Table from '../index';
import '../assets/index.less';
import Menu from '../../menu';
const Item = Menu.Item;
const Divider = Menu.Divider;
import DropDown from '../../dropdown';
2018-03-26 11:05:40 +00:00
2019-01-12 03:33:27 +00:00
const data = [];
2018-03-26 11:05:40 +00:00
for (let i = 0; i < 10; i++) {
data.push({
key: i,
a: `a${i}`,
b: `b${i}`,
c: `c${i}`,
2019-01-12 03:33:27 +00:00
});
2018-03-26 11:05:40 +00:00
}
export default {
2019-01-12 03:33:27 +00:00
data() {
this.filters = [];
2018-03-26 11:05:40 +00:00
return {
visible: false,
2019-01-12 03:33:27 +00:00
};
2018-03-26 11:05:40 +00:00
},
methods: {
2019-01-12 03:33:27 +00:00
handleVisibleChange(visible) {
this.visible = visible;
2018-03-26 11:05:40 +00:00
},
2019-01-12 03:33:27 +00:00
handleSelect(selected) {
this.filters.push(selected);
2018-03-26 11:05:40 +00:00
},
2019-01-12 03:33:27 +00:00
handleDeselect(key) {
const index = this.filters.indexOf(key);
2018-03-26 11:05:40 +00:00
if (index !== -1) {
2019-01-12 03:33:27 +00:00
this.filters.splice(index, 1);
2018-03-26 11:05:40 +00:00
}
},
2019-01-12 03:33:27 +00:00
confirmFilter() {
console.log(this.filters.join(','));
this.visible = false;
2018-03-26 11:05:40 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
2018-03-26 11:05:40 +00:00
const menu = (
<Menu
style={{ width: '200px' }}
multiple
selectable
onSelect={this.handleSelect}
onDeselect={this.handleDeselect}
>
2019-01-12 03:33:27 +00:00
<Item key="1">one</Item>
<Item key="2">two</Item>
<Item key="3">three</Item>
2018-03-26 11:05:40 +00:00
<Divider />
<Item disabled>
<button
style={{
cursor: 'pointer',
color: '#000',
pointerEvents: 'visible',
}}
onClick={this.confirmFilter}
2019-01-12 03:33:27 +00:00
>
确定
</button>
2018-03-26 11:05:40 +00:00
</Item>
</Menu>
2019-01-12 03:33:27 +00:00
);
2018-03-26 11:05:40 +00:00
const columns = [
{
title: (
<div>
title1
<DropDown
trigger={['click']}
onVisibleChange={this.handleVisibleChange}
visible={this.visible}
>
2019-01-12 03:33:27 +00:00
<template slot="overlay">{menu}</template>
<a href="#">filter</a>
2018-03-26 11:05:40 +00:00
</DropDown>
</div>
2019-01-12 03:33:27 +00:00
),
key: 'a',
dataIndex: 'a',
width: 100,
2018-03-26 11:05:40 +00:00
},
{ title: 'title2', key: 'b', dataIndex: 'b', width: 100 },
{ title: 'title3', key: 'c', dataIndex: 'c', width: 200 },
2019-01-12 03:33:27 +00:00
];
2018-03-26 11:05:40 +00:00
return (
<div>
<h2>use dropdown</h2>
2019-01-12 03:33:27 +00:00
<Table columns={columns} data={data} rowKey={record => record.key} />
2018-03-26 11:05:40 +00:00
</div>
2019-01-12 03:33:27 +00:00
);
2018-03-26 11:05:40 +00:00
},
2019-01-12 03:33:27 +00:00
};