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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ React.render(<Table columns={columns} data={data} />, mountNode);
<th></th>
<td>handle rowClick action, index means the index of current row among fatherElement[childrenColumnName]</td>
</tr>
<tr>
<td>onRowDoubleClick</td>
<td>Function(record, index)</td>
<th></th>
<td>handle rowDoubleClick action, index means the index of current row among fatherElement[childrenColumnName]</td>
</tr>
<tr>
<td>columnsPageSize</td>
<td>Number</td>
Expand Down
21 changes: 16 additions & 5 deletions examples/rowClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ const Table = require('rc-table');
require('rc-table/assets/index.less');

const onRowClick = (record, index, event) => {
console.log(`click nth(${index}) element of parent, record.name: ${record.name}`);
console.log(`Click nth(${index}) element of parent, record.name: ${record.name}`);
// See https://facebook.github.io/react/docs/events.html for original click event details.
if (event.shiftKey) {
console.log('Shift + mouse click triggered.');
}
};

const onOperationClick = (text, record) => {
console.log(`click ${text}, record.name is ${record.name}`);
const onRowDoubleClick = (record, index) => {
console.log(`Double click nth(${index}) element of parent, record.name: ${record.name}`);
};

const onOperationClick = (text, record, event) => {
event.preventDefault();
event.stopPropagation();
console.log(`Click Cell ${text}, record.name is ${record.name}`);
};

const columns = [{
Expand All @@ -27,7 +33,7 @@ const columns = [{
key: 'age',
width: 100,
render: (text, record) => (
<a href="#" onClick={onOperationClick.bind(null, text, record)}>
<a href="#" onClick={e => onOperationClick(text, record, e)}>
Alert: {text}, click will pop to row click
</a>
),
Expand Down Expand Up @@ -90,6 +96,11 @@ const data = [{
}];

ReactDOM.render(
<Table columns={columns} data={data} onRowClick={onRowClick} />,
<Table
columns={columns}
data={data}
onRowClick={onRowClick}
onRowDoubleClick={onRowDoubleClick}
/>,
document.getElementById('__react-content')
);
5 changes: 5 additions & 0 deletions src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Table = React.createClass({
onExpandedRowsChange: PropTypes.func,
indentSize: PropTypes.number,
onRowClick: PropTypes.func,
onRowDoubleClick: PropTypes.func,
columnsPageRange: PropTypes.array,
columnsPageSize: PropTypes.number,
expandIconColumnIndex: PropTypes.number,
Expand All @@ -49,6 +50,8 @@ const Table = React.createClass({
expandedRowClassName: () => '',
onExpand() {},
onExpandedRowsChange() {},
onRowClick() {},
onRowDoubleClick() {},
prefixCls: 'rc-table',
bodyStyle: {},
style: {},
Expand Down Expand Up @@ -278,6 +281,7 @@ const Table = React.createClass({
const expandedRowClassName = props.expandedRowClassName;
const needIndentSpaced = props.data.some(record => record[childrenColumnName]);
const onRowClick = props.onRowClick;
const onRowDoubleClick = props.onRowDoubleClick;
const isAnyColumnsFixed = this.isAnyColumnsFixed();

const expandIconAsCell = fixed !== 'right' ? props.expandIconAsCell : false;
Expand Down Expand Up @@ -328,6 +332,7 @@ const Table = React.createClass({
columns={leafColumns}
expandIconColumnIndex={expandIconColumnIndex}
onRowClick={onRowClick}
onRowDoubleClick={onRowDoubleClick}
style={style}
{...onHoverProps}
key={key}
Expand Down
11 changes: 9 additions & 2 deletions src/TableRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const TableRow = React.createClass({
propTypes: {
onDestroy: PropTypes.func,
onRowClick: PropTypes.func,
onRowDoubleClick: PropTypes.func,
record: PropTypes.object,
prefixCls: PropTypes.string,
expandIconColumnIndex: PropTypes.number,
Expand All @@ -30,6 +31,7 @@ const TableRow = React.createClass({
getDefaultProps() {
return {
onRowClick() {},
onRowDoubleClick() {},
onDestroy() {},
expandIconColumnIndex: 0,
expandRowByClick: false,
Expand All @@ -54,14 +56,18 @@ const TableRow = React.createClass({
expandRowByClick,
expanded,
onExpand,
} = this.props;

} = this.props;
if (expandable && expandRowByClick) {
onExpand(!expanded, record);
}
onRowClick(record, index, event);
},

onRowDoubleClick(event) {
const { record, index, onRowDoubleClick } = this.props;
onRowDoubleClick(record, index, event);
},

onMouseEnter() {
const { onHover, hoverKey } = this.props;
onHover(true, hoverKey);
Expand Down Expand Up @@ -122,6 +128,7 @@ const TableRow = React.createClass({
return (
<tr
onClick={this.onRowClick}
onDoubleClick={this.onRowDoubleClick}
onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
className={`${prefixCls} ${className} ${prefixCls}-level-${indent}`}
Expand Down