Skip to content
Merged
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
30 changes: 21 additions & 9 deletions src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,29 @@ class Table extends React.Component {
}

getThs() {
return this.props.columns.map((c)=> {
var expandIconAsCell = this.props.expandIconAsCell === false ? false : true;
var ths = [];
if (expandIconAsCell) {
ths.push({
title: ''
});
}
ths = ths.concat(this.props.columns);
return ths.map((c)=> {
return <th key={c.key} className={c.className || ''}>{c.title}</th>;
});
}

getExpandedRow(key, content, visible, className) {
var expandIconAsCell = this.props.expandIconAsCell === false ? false : true;
var prefixCls = this.props.prefixCls;
if (key) {
key += '-extra-row';
}
return <tr key={key} style={{display: visible ? '' : 'none'}} className={`${prefixCls}-expanded-row ${className}`}>
{expandIconAsCell ? <td></td> : ''}
<td colSpan={this.props.columns.length}>
{content}
{content}
</td>
</tr>;
}
Expand All @@ -81,6 +91,7 @@ class Table extends React.Component {
var columns = props.columns;
var childrenColumnName = props.childrenColumnName;
var expandedRowRender = props.expandedRowRender;
var expandIconAsCell = props.expandIconAsCell;
var rst = [];
var keyFn = props.rowKey;
var rowClassName = props.rowClassName;
Expand All @@ -97,6 +108,7 @@ class Table extends React.Component {
rst.push(<TableRow
className={className}
record={record}
expandIconAsCell={expandIconAsCell}
onDestroy={this.handleRowDestroy}
index={i}
visible={visible}
Expand Down Expand Up @@ -142,26 +154,26 @@ class Table extends React.Component {
}
var headerTable;
var thead = <thead className={`${prefixCls}-thead`}>
<tr>
{columns}
</tr>
<tr>
{columns}
</tr>
</thead>;
if (props.useFixedHeader) {
headerTable = <div className={`${prefixCls}-header`}>
<table>
{this.getColGroup()}
{this.getColGroup()}
{thead}
</table>
</div>;
thead = null;
}
return (
<div className={className} style={props.style}>
{headerTable}
{headerTable}
<div className={`${prefixCls}-body`} style={props.bodyStyle}>
<table>
{this.getColGroup()}
{thead}
{this.getColGroup()}
{thead}
<tbody className={`${prefixCls}-tbody`}>
{rows}
</tbody>
Expand Down
56 changes: 41 additions & 15 deletions src/TableRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,53 @@ class TableRow extends React.Component {
var index = props.index;
var cells = [];
var expanded = props.expanded;
for (var i = 0; i < columns.length; i++) {
var col = columns[i];
var colClassName = col.className || '';
var render = col.render;
var text = record[col.dataIndex];
var expandable = props.expandable;
var expandIconAsCell = props.expandIconAsCell === false ? false : true;

if (expandIconAsCell) {
if (expandable) {
cells.push(<td>
{<span
className={`${prefixCls}-expand-icon ${prefixCls}-${expanded ? 'expanded' : 'collapsed'}`}
onClick={props.onExpand.bind(null, !expanded, record)}
></span>}
</td>);
} else {
cells.push(<td></td>);
}
if (!columns[0].title) {
columns.shift();
}
} else {
let col = columns[0];
let text = record[col.dataIndex];
if (expandable) {
cells.push(<td>
{<span
className={`${prefixCls}-expand-icon ${prefixCls}-${expanded ? 'expanded' : 'collapsed'}`}
onClick={props.onExpand.bind(null, !expanded, record)}
></span>}
{text}
</td>);
} else {
cells.push(<td>{text}</td>);
}
}

for (var i = expandIconAsCell ? 0 : 1; i < columns.length; i++) {
let col = columns[i];
let colClassName = col.className || '';
let render = col.render;
let text = record[col.dataIndex];
if (render) {
text = render(text, record, index);
}
var expandIcon = null;
if (props.expandable && i === 0) {
expandIcon = <span
className={`${prefixCls}-expand-icon ${prefixCls}-${expanded ? 'expanded' : 'collapsed'}`}
onClick={props.onExpand.bind(null, !expanded, record)}
></span>;
}
cells.push(<td key={col.key} className={`${colClassName}`}>
{expandIcon}
{text}
{text}
</td>);
}
return (<tr className={`${prefixCls} ${props.className}`} style={{display: props.visible ? '' : 'none'}}>{cells}</tr>);
return (
<tr className={`${prefixCls} ${props.className}`} style={{display: props.visible ? '' : 'none'}}>{cells}</tr>);
}
}

Expand Down