React-bootstrap-table2: Custom content in cells

Created on 14 Mar 2018  路  4Comments  路  Source: react-bootstrap-table/react-bootstrap-table2

How do we add custom content to cells, like newlines (to have contents of same cell break into 2 lines) or to have buttons (or any other React component) in cells?

Most helpful comment

There's a formatter prop, maybe that's what you're looking for (example below is for a column which contains a "remove" button :

const deleteFormatter = (cell, row, rowIndex, formatExtraData) => { const { deleteMe } = props; const rowId = row.id; return ( <Button icon labelPosition='left' onClick={() => deleteMe(rowIndex, rowId)}> <Icon name='remove' /> Remove </Button> ); }

const enhancedColumns = [...columns, { dataField: 'edit', text: '', editable: false, align: "center", headerStyle: { width: 120 }, formatter: deleteFormatter }

All 4 comments

There's a formatter prop, maybe that's what you're looking for (example below is for a column which contains a "remove" button :

const deleteFormatter = (cell, row, rowIndex, formatExtraData) => { const { deleteMe } = props; const rowId = row.id; return ( <Button icon labelPosition='left' onClick={() => deleteMe(rowIndex, rowId)}> <Icon name='remove' /> Remove </Button> ); }

const enhancedColumns = [...columns, { dataField: 'edit', text: '', editable: false, align: "center", headerStyle: { width: 120 }, formatter: deleteFormatter }

Thanks, @philohelp! I solved it via the same way as you suggested. Made a function that returns a component I made just for that column's cells. Cheers.

@philohelp thanks!!

There's a formatter prop, maybe that's what you're looking for (example below is for a column which contains a "remove" button :

const deleteFormatter = (cell, row, rowIndex, formatExtraData) => { const { deleteMe } = props; const rowId = row.id; return ( <Button icon labelPosition='left' onClick={() => deleteMe(rowIndex, rowId)}> <Icon name='remove' /> Remove </Button> ); }

const enhancedColumns = [...columns, { dataField: 'edit', text: '', editable: false, align: "center", headerStyle: { width: 120 }, formatter: deleteFormatter }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ethannkschneider picture ethannkschneider  路  3Comments

josefheld picture josefheld  路  3Comments

epsyan picture epsyan  路  4Comments

cnav007 picture cnav007  路  4Comments

harishkumarreddy12 picture harishkumarreddy12  路  3Comments