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

126 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-03-27 14:41:41 +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';
2018-03-27 14:41:41 +00:00
const onRowClick = (record, index, event) => {
2019-01-12 03:33:27 +00:00
console.log(`Click nth(${index}) row of parent, record.name: ${record.name}`);
2018-03-27 14:41:41 +00:00
// See https://facebook.github.io/react/docs/events.html for original click event details.
if (event.shiftKey) {
2019-01-12 03:33:27 +00:00
console.log('Shift + mouse click triggered.');
2018-03-27 14:41:41 +00:00
}
2019-01-12 03:33:27 +00:00
};
2018-03-27 14:41:41 +00:00
2018-03-31 09:46:35 +00:00
const onRowDoubleClick = (record, index, e) => {
2019-01-12 03:33:27 +00:00
console.log(`Double click nth(${index}) row of parent, record.name: ${record.name}`, e);
};
2018-03-27 14:41:41 +00:00
2019-01-12 03:33:27 +00:00
const data = [
{
key: 1,
name: 'a',
age: 32,
address: 'I am a',
children: [
{
key: 11,
name: 'aa',
2018-03-27 14:41:41 +00:00
age: 33,
2019-01-12 03:33:27 +00:00
address: 'I am aa',
},
{
key: 12,
name: 'ab',
2018-03-27 14:41:41 +00:00
age: 33,
2019-01-12 03:33:27 +00:00
address: 'I am ab',
children: [
{
key: 121,
name: 'aba',
age: 33,
address: 'I am aba',
},
],
},
{
key: 13,
name: 'ac',
age: 33,
address: 'I am ac',
children: [
{
key: 131,
name: 'aca',
age: 33,
address: 'I am aca',
children: [
{
key: 1311,
name: 'acaa',
age: 33,
address: 'I am acaa',
},
{
key: 1312,
name: 'acab',
age: 33,
address: 'I am acab',
},
],
},
],
},
],
},
{
key: 2,
name: 'b',
age: 32,
address: 'I am b',
},
];
2018-03-27 14:41:41 +00:00
export default {
2019-01-12 03:33:27 +00:00
render() {
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
width: 400,
},
{
title: 'Age',
dataIndex: 'age',
key: 'age',
width: 100,
customRender: text => <span>{text} (Trigger Cell Click)</span>,
customCell: (record, index) => ({
on: {
click(e) {
console.log('Click cell', ` row ${index}`, record, e.target);
},
2018-04-04 02:29:42 +00:00
},
2019-01-12 03:33:27 +00:00
}),
},
{
title: 'Address',
dataIndex: 'address',
key: 'address',
width: 200,
},
];
2018-03-27 14:41:41 +00:00
return (
<Table
columns={columns}
data={data}
2018-03-31 09:46:35 +00:00
customRow={(record, index) => ({
2018-03-27 14:41:41 +00:00
on: {
click: onRowClick.bind(null, record, index),
dblclick: onRowDoubleClick.bind(null, record, index),
},
})}
/>
2019-01-12 03:33:27 +00:00
);
2018-03-27 14:41:41 +00:00
},
2019-01-12 03:33:27 +00:00
};