react-data-table-component icon indicating copy to clipboard operation
react-data-table-component copied to clipboard

String does not appear in column

Open slimandslam opened this issue 3 years ago • 4 comments

The code is simple. What I want to do is have the string '---' appear if fileName is empty and display fileName if fileName contains any content.

What happens is that fileName does appear if fileName is a non-empty string, but if fileName is empty, nothing appears (instead of '---')

Data Table version 7.5 React 17.02

const columns = [
 {
      name: "Filename",
      selector: "fileName",
      format: (d) => (d.fileName === '' ? ' --- ' : d.fileName),
      width: "160px",
      cell: Cell("fileName"),
    }
]

slimandslam avatar Apr 20 '22 22:04 slimandslam

Cell supersedes format. You'll want to use one or the other.

jbetancur avatar May 05 '22 01:05 jbetancur

I can't seem to get it to accept both a conditional and tooltips. I tried something like this:

format: (d) => (d.fileName === '' ? ' --- ' : <span style={{whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis"}} title={d.filename}>{d.filename}</span>),

slimandslam avatar May 07 '22 02:05 slimandslam

Try the cell property. Format is meant for simpler use cases.

jbetancur avatar May 07 '22 11:05 jbetancur

I ended up using format:

format: (d) => (d.fileName === '' ? ' --- ' : <span style={{whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis"}} title={d.fileName}>{d.fileName}</span>),

slimandslam avatar May 07 '22 15:05 slimandslam