Search code examples
javascriptreactjsmaterial-table

Material-Table is ignoring \n separators in data


I have a field in my Material-Table which contains a very long string. The string contains \n separators but the table is just ignoring these.

I have tried using \n\n, \r, \r\n, \n\r. None of these have worked.

Here is a quick example of the the field:

"Domain: Corporate, DomainLeader: John Doe,\n Experience: Finance,\n ExperienceLeader: Jane Doe,\n ProductLine: Finance Systems,\n ProductLineLeader: John Doe"

Solution

  • Setting render instructions onto the column to add a <br> after each comma has solved this issue for me

    {
                title: <Typography className={classes.colHeader}>Taxonomy</Typography>,
                field: "Taxonomy",
                cellStyle: { minWidth: 400, maxWidth: 400 },
                render: (rowData) => (
                    <Box style={{ flexDirection: "row" }}>
                        {rowData.Taxonomy.split(", ").map((b) => (
                            <Box style={{ display: "flex" }}>
                                <Box style={{ fontWeight: "bold" }}>{b.split(":")[0]}:</Box>
                                <Box>&nbsp;{b.split(":")[1]},</Box>
                            </Box>
                        ))}
                    </Box>
                ),
            },