react-bootstrap-table / react-bootstrap-table2

Next Generation of react-bootstrap-table
https://react-bootstrap-table.github.io/react-bootstrap-table2/
MIT License
1.26k stars 430 forks source link

Font-Awesome Icon Not Rendering #1574

Open trig79 opened 3 years ago

trig79 commented 3 years ago

Question Font Awesome Icons are not rendering in Table, am I doing something wrong? I have checked outside the table and they render fine. I am using formatExtraData and have tested rendering RAW text and that works fine, so the issue is just with the Icons themselves, are they supported?

Code dataField: 'isAdmin', text: 'Adm', formatter: (cell, row, rowIndex, formatExtraData) => { return <i className={formatExtraData[cell]}></i> }, formatExtraData: { 0: "'fas fa-check' style={{ color: 'green' }}", 1: "'fas fa-times' style={{ color: 'red' }}", },

jklingen92 commented 3 years ago

@trig79 Your code results in this:

<i className={"'fas fa-check' style={{ color: 'green' }}"}></>

You have too many quotation marks and also your setting style=... as a class, not an attribute. Instead of using formatExtraData, why don't you just say

formatter: (cell) => {
  if (cell === 0) {
    props={className: 'fas fa-check', style={color: 'green'}}
  } // any other cases
  return <i {...prop}></i> }
}