From feedcb9f4bafef77a5f87cf4f228a82445f1825c Mon Sep 17 00:00:00 2001 From: Parth Prajapati Date: Wed, 31 Jan 2018 07:43:05 +0530 Subject: [PATCH 1/3] Solves #179 --- .../examples/rows/row-event.js | 8 ++++---- packages/react-bootstrap-table2/src/row.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) 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..d65d99a 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, rowIndex) => { + alert(`clicked on row with index: ${rowIndex}`); } }; @@ -40,8 +40,8 @@ const columns = [{ }]; const rowEvents = { - onClick: (e) => { - alert('click on row'); + onClick: (e, 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 24f443a..6edaac9 100644 --- a/packages/react-bootstrap-table2/src/row.js +++ b/packages/react-bootstrap-table2/src/row.js @@ -12,6 +12,7 @@ class Row extends Component { super(props); this.clickNum = 0; this.handleRowClick = this.handleRowClick.bind(this); + this.handleSimpleRowClick = this.handleSimpleRowClick.bind(this); } handleRowClick(e) { @@ -56,6 +57,15 @@ class Row extends Component { } } + handleSimpleRowClick(e) { + const { + rowIndex, + attrs + } = this.props; + + attrs.onClick(e, rowIndex); + } + render() { const { row, @@ -89,6 +99,8 @@ class Row extends Component { const trAttrs = { ...attrs }; if (clickToSelect) { trAttrs.onClick = this.handleRowClick; + } else { + trAttrs.onClick = this.handleSimpleRowClick; } return ( From c4f14e2b69f9390b6fb827c89f39d34b563fa254 Mon Sep 17 00:00:00 2001 From: Parth Prajapati Date: Thu, 1 Feb 2018 06:20:50 +0530 Subject: [PATCH 2/3] Added row object to onClick - attach onClick only if defined --- .../examples/rows/row-event.js | 2 +- packages/react-bootstrap-table2/src/row.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) 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 d65d99a..0fb8db1 100644 --- a/packages/react-bootstrap-table2-example/examples/rows/row-event.js +++ b/packages/react-bootstrap-table2-example/examples/rows/row-event.js @@ -20,7 +20,7 @@ const columns = [{ }]; const rowEvents = { - onClick: (e, rowIndex) => { + 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 6edaac9..42f235e 100644 --- a/packages/react-bootstrap-table2/src/row.js +++ b/packages/react-bootstrap-table2/src/row.js @@ -36,7 +36,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); @@ -59,11 +59,12 @@ class Row extends Component { handleSimpleRowClick(e) { const { + row, rowIndex, attrs } = this.props; - attrs.onClick(e, rowIndex); + attrs.onClick(e, row, rowIndex); } render() { @@ -99,7 +100,7 @@ class Row extends Component { const trAttrs = { ...attrs }; if (clickToSelect) { trAttrs.onClick = this.handleRowClick; - } else { + } else if (attrs.onClick) { trAttrs.onClick = this.handleSimpleRowClick; } From 577973a147ceab68ad4370c003bcd1351154b9b0 Mon Sep 17 00:00:00 2001 From: Parth Prajapati Date: Thu, 1 Feb 2018 06:27:49 +0530 Subject: [PATCH 3/3] Updated storybook example --- .../react-bootstrap-table2-example/examples/rows/row-event.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0fb8db1..1a57fb6 100644 --- a/packages/react-bootstrap-table2-example/examples/rows/row-event.js +++ b/packages/react-bootstrap-table2-example/examples/rows/row-event.js @@ -40,7 +40,7 @@ const columns = [{ }]; const rowEvents = { - onClick: (e, rowIndex) => { + onClick: (e, row, rowIndex) => { alert(\`clicked on row with index: \${rowIndex}\`); } };