Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onRowClick for react-bootstrap-table

Trying to get onRowClick to work, but nothing is happening when I click on the row.

    <BootstrapTable data={products} onRowClick={this.onClickHandler.bind(this)} striped={true} hover={true} pagination={true} search={true} searchPlaceholder="Search">
        <TableHeaderColumn isKey={true} dataField="_id">Customer ID</TableHeaderColumn>
        <TableHeaderColumn dataField="customername" >Customer Name</TableHeaderColumn>
        <TableHeaderColumn dataField="address">Address</TableHeaderColumn>
        <TableHeaderColumn dataField="city">City</TableHeaderColumn>
        <TableHeaderColumn dataField="createdate">Last Order Date</TableHeaderColumn>
        <TableHeaderColumn dataField="style">Style</TableHeaderColumn>
        <TableHeaderColumn dataField="dimensions">Dimensions</TableHeaderColumn>
    </BootstrapTable>
like image 932
user3877502 Avatar asked Apr 27 '16 05:04

user3877502


2 Answers

Sorry just figured it out

have to set options

var options = {
 onRowClick: function(row){
 }
}

<BootstrapTable data={products} options={options} ...
like image 144
user3877502 Avatar answered Oct 13 '22 22:10

user3877502


For me I am using react-bootstrap-table-next - v 4.0.3 and the above solution didn't work for some reason. Where as the following implementation worked.

const tableRowEvents = {
   onClick: (e, row, rowIndex) => {
     console.log(`clicked on row with index: ${rowIndex}`);
   },
   onMouseEnter: (e, row, rowIndex) => {
     console.log(`enter on row with index: ${rowIndex}`);
   }
}

<BootstrapTable
      hover
      bordered={false}
      bootstrap4
      keyField={"apps.App"}
      data={apps ? apps : no_Data}
      columns={columns}
      rowEvents={ tableRowEvents }
/>

I followed the documentation from react-bootstrap-table2

like image 27
yodellingbutters Avatar answered Oct 13 '22 22:10

yodellingbutters