gregnb / mui-datatables

Datatables for React using Material-UI
MIT License
2.71k stars 932 forks source link

Multiline column name does not work with strings #437

Open gabsbelini opened 5 years ago

gabsbelini commented 5 years ago

I'm trying to add a column name that has a multiline string, i.e: ${line1}\n${line2} But the result is: "line1line2"

Expected Behavior

What I wanted to see is:

line1
line2

Current Behavior

What I see:

line1line2

Workaround

The problem does not happen if a use an HTML object instead of a template string such as:

<div>
    <div>line1</div>
    <div>line2</div>
</div>

But then when I download the table data I get [object Object] for the referred column

Your Environment

Tech Version
@material-ui/core 3.8.3
MUI-datatables 2.0.0-beta-32
React 16.5.2
browser chrome
gabrielliwerant commented 5 years ago

I believe this is actually intended behavior as per the template literal specifications: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals.

The way around this is to actually put the break in the string:

const lineBreak = `first line
second line`;

Alternatively, check out the tagged templates documentation for more advanced functionality https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates, or a helper library like https://www.npmjs.com/package/common-tags.

andrewphan568 commented 3 years ago

I get the same issue. And I use React Typescript with not allow me to use the above workaround. Is there any update on this issue?