Skip to content

Table中有空数据时设置默认文本显示,column可自定义默认文本,并且优先级高于table #2109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default {
props: initDefaultProps(TableProps, {
dataSource: [],
useFixedHeader: false,
tableDefaultText: '无',
// rowSelection: null,
size: 'default',
loading: false,
Expand Down Expand Up @@ -1199,6 +1200,11 @@ export default {
}).map((column, i) => {
const newColumn = { ...column };
newColumn.key = getColumnKey(newColumn, i);
if (!newColumn.columnDefaultText) {
if (restProps.tableDefaultText) {
newColumn.columnDefaultText = restProps.tableDefaultText;
}
}
return newColumn;
});

Expand Down
2 changes: 2 additions & 0 deletions components/table/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const ColumnProps = {
dataIndex: PropTypes.string,
customRender: PropTypes.func,
customCell: PropTypes.func,
columnDefaultText: PropTypes.string,
customHeaderCell: PropTypes.func,
align: PropTypes.oneOf(['left', 'right', 'center']),
ellipsis: PropTypes.bool,
Expand Down Expand Up @@ -92,6 +93,7 @@ export const TableRowSelection = {

export const TableProps = {
prefixCls: PropTypes.string,
tableDefaultText: PropTypes.string,
dropdownPrefixCls: PropTypes.string,
rowSelection: PropTypes.oneOfType([PropTypes.shape(TableRowSelection).loose, null]),
pagination: PropTypes.oneOfType([
Expand Down
1 change: 1 addition & 0 deletions components/vc-table/src/Column.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
colSpan: PropTypes.number,
title: PropTypes.any,
dataIndex: PropTypes.string,
columnDefaultText: PropTypes.string,
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
ellipsis: PropTypes.bool,
fixed: PropTypes.oneOf([true, 'left', 'right']),
Expand Down
1 change: 1 addition & 0 deletions components/vc-table/src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
{
data: PropTypes.array,
useFixedHeader: PropTypes.bool,
tableDefaultText: PropTypes.string,
columns: PropTypes.array,
prefixCls: PropTypes.string,
bodyStyle: PropTypes.object,
Expand Down
8 changes: 4 additions & 4 deletions components/vc-table/src/TableCell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ export default {
column,
component: BodyCell,
} = this;
const { dataIndex, customRender, className = '' } = column;
const { dataIndex, customRender, className = '', columnDefaultText } = column;
// 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.
let text;
if (typeof dataIndex === 'number') {
text = get(record, dataIndex);
text = get(record, dataIndex) || columnDefaultText;
} else if (!dataIndex || dataIndex.length === 0) {
text = record;
text = record || columnDefaultText;
} else {
text = get(record, dataIndex);
text = get(record, dataIndex) || columnDefaultText;
}
let tdProps = {
props: {},
Expand Down