diff --git a/packages/react-bootstrap-table2-example/examples/rows/row-event.js b/packages/react-bootstrap-table2-example/examples/rows/row-event.js index 915f9af..1a57fb6 100644 --- a/packages/react-bootstrap-table2-example/examples/rows/row-event.js +++ b/packages/react-bootstrap-table2-example/examples/rows/row-event.js @@ -20,8 +20,8 @@ const columns = [{ }]; const rowEvents = { - onClick: (e) => { - alert('click on row'); + onClick: (e, row, rowIndex) => { + alert(`clicked on row with index: ${rowIndex}`); } }; @@ -40,8 +40,8 @@ const columns = [{ }]; const rowEvents = { - onClick: (e) => { - alert('click on row'); + onClick: (e, row, rowIndex) => { + alert(\`clicked on row with index: \${rowIndex}\`); } }; diff --git a/packages/react-bootstrap-table2/src/row.js b/packages/react-bootstrap-table2/src/row.js index fa723af..1b55628 100644 --- a/packages/react-bootstrap-table2/src/row.js +++ b/packages/react-bootstrap-table2/src/row.js @@ -13,6 +13,7 @@ class Row extends Component { super(props); this.clickNum = 0; this.handleRowClick = this.handleRowClick.bind(this); + this.handleSimpleRowClick = this.handleSimpleRowClick.bind(this); } handleRowClick(e) { @@ -36,7 +37,7 @@ class Row extends Component { const clickFn = () => { if (attrs.onClick) { - attrs.onClick(e); + attrs.onClick(e, row, rowIndex); } if (selectable) { const key = _.get(row, keyField); @@ -57,6 +58,16 @@ class Row extends Component { } } + handleSimpleRowClick(e) { + const { + row, + rowIndex, + attrs + } = this.props; + + attrs.onClick(e, row, rowIndex); + } + render() { const { row, @@ -90,6 +101,8 @@ class Row extends Component { const trAttrs = { ...attrs }; if (clickToSelect) { trAttrs.onClick = this.handleRowClick; + } else if (attrs.onClick) { + trAttrs.onClick = this.handleSimpleRowClick; } return (