Passing react-router <Link> component to the table cell
Hello,
got a problem trying to create a hyperlink inside a table cell using react-router component.
I wrote the following function:
function tenantLinkFormat(cell, row) {
const link = <Link to="/users">cell</Link>;
console.log(cell);
console.log(link);
return link;
}
And got this error message in console:
warning.js:36 Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of
TableBody.
The console output with the objects looks as follows: http://i.imgur.com/RyFGBCD.png
So it seems to me that everything is correct, but it isn't apparently. Please point me to what should be fixed here.
@polyakoff, it's a improvement item that I'll fix it in the future. Because I doesn't make react-bootstrap-table fully capable for newest react.
@AllenFang Got it, thanks. Could you give a tip how to workaround this?
@polyakoff, I think it cant be done on in your repo, It need to change the source codes~
I am thinking of a possibility or an option of exposing a function on the table row such that once the row is clicked, function can retrieve the id/unique key of the row which could be further used to redirect to a link built using the id/unique key. This option could be enabled and disabled at will taking into consideration that inline editing is needed at times.
Also, an extra cell could be added on each record that will host a link.
Another possibility is to be able to detect the propTypes of the props passed by data and render them accordingly.
Hope a work around is implemented asap Courage.
@bnlambert, thanks your advice, you can check this example.
Also, an extra cell could be added on each record that will host a link.
I'm not sure which this means.
You can do transitions with React Router v4 without <Link />:
https://github.com/ReactTraining/react-router/issues/4220
That might be a workaround here.
also, wouldn't this work:
<TableHeaderColumn dataField='id' dataFormat={ this.colFormatter }>my header</TableHeaderColumn>
...and then:
colFormatter = (cell, row) => {
return (
<Link to='/some/route'>
{cell}
</Link>
)
}
That appears to work for me.
@bmueller-sykes thanks your finding. Open this issue if someone still have the same issue. Thanks
To navigate using a React Router, you can disable default behavior and turn on the onClick
`import React, { Component } from 'react' import { Route } from 'react-router-dom' import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table' .... class LinkTable extends Component {
hrefIdFormatter = (cell, row) => {
const href = product/${row.id};
return (
<Route render={({ history }) => (
<a href={href} style={{ cursor: 'pointer' }}
onClick={(e) => {
// stop default behavior a href
e.preventDefault();
// set state selected product id
this.set({ ...this.state, selected: row.id });
// go to the detail product page
history.push(/product/${row.id})
}}>
{row.id}
)}
/>)
}
render() {
return (
also, wouldn't this work:
<TableHeaderColumn dataField='id' dataFormat={ this.colFormatter }>my header</TableHeaderColumn>...and then:
colFormatter = (cell, row) => { return ( <Link to='/some/route'> {cell} </Link> ) }That appears to work for me.
@bmueller-sykes thanks your finding. Open this issue if someone still have the same issue. Thanks
Can i use this solution in react-bootstrap-table2? What would you recommend between react-bootstrap-table and react-bootstrap-table2? Thank you!