1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import PropTypes from '../../_util/vue-types';
import get from 'lodash/get';
import { isValidElement, mergeProps } from '../../_util/props-util';
function isInvalidRenderCellText(text) {
return text && !isValidElement(text) && Object.prototype.toString.call(text) === '[object Object]';
}
export default {
name: 'TableCell',
props: {
record: PropTypes.object,
prefixCls: PropTypes.string,
index: PropTypes.number,
indent: PropTypes.number,
indentSize: PropTypes.number,
column: PropTypes.object,
expandIcon: PropTypes.any,
component: PropTypes.any
},
methods: {
handleClick: function handleClick(e) {
var record = this.record,
onCellClick = this.column.onCellClick;
if (onCellClick) {
onCellClick(record, e);
}
}
},
render: function render() {
var h = arguments[0];
var record = this.record,
indentSize = this.indentSize,
prefixCls = this.prefixCls,
indent = this.indent,
index = this.index,
expandIcon = this.expandIcon,
column = this.column,
BodyCell = this.component;
var dataIndex = column.dataIndex,
customRender = column.customRender,
_column$className = column.className,
className = _column$className === undefined ? '' : _column$className;
var cls = className || column['class'];
// We should return undefined if no dataIndex is specified, but in order to
// be compatible with object-path's behavior, we return the record object instead.
var text = void 0;
if (typeof dataIndex === 'number') {
text = get(record, dataIndex);
} else if (!dataIndex || dataIndex.length === 0) {
text = record;
} else {
text = get(record, dataIndex);
}
var tdProps = {
props: {},
attrs: {},
'class': cls,
on: {
click: this.handleClick
}
};
var colSpan = void 0;
var rowSpan = void 0;
if (customRender) {
text = customRender(text, record, index);
if (isInvalidRenderCellText(text)) {
tdProps.attrs = text.attrs || {};
tdProps.props = text.props || {};
colSpan = tdProps.attrs.colSpan;
rowSpan = tdProps.attrs.rowSpan;
text = text.children;
}
}
if (column.customCell) {
tdProps = mergeProps(tdProps, column.customCell(record, index));
}
// Fix https://github.com/ant-design/ant-design/issues/1202
if (isInvalidRenderCellText(text)) {
text = null;
}
var indentText = expandIcon ? h('span', {
style: { paddingLeft: indentSize * indent + 'px' },
'class': prefixCls + '-indent indent-level-' + indent
}) : null;
if (rowSpan === 0 || colSpan === 0) {
return null;
}
if (column.align) {
tdProps.style = { textAlign: column.align };
}
return h(
BodyCell,
tdProps,
[indentText, expandIcon, text]
);
}
};