How to force a line break in header

How to force a line break in header

andre_tuxandre_tux Posts: 2Questions: 1Answers: 0

I am using DataTables with Bootstrap4 and we would like to force a line break in the header, even though the column width does not require it.

For example: Vendor Name
It should display in the header as:

Vendor
Name

I have tried the usual suspects like :

Vendor<br>Name
Vendor Name
Vendor\nName

But noting works. The text is printed in the header as is, with all the tags and codes.

Is there a way to force the newline?

Thanks
Andre

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Using </br> works here with Bootstrap 4:
    http://live.datatables.net/yahipoki/1/edit

    Please update the example or provide a link to a test case showing the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • andre_tuxandre_tux Posts: 2Questions: 1Answers: 0

    We generate the code for the table dynamically from a database, so that the reports are configurable and that seems to be the problem.

    The header is read from the database with PHP and it creates the HTML code like this:

    $header .=<<<EOT
    <th>{$h}</th>
    EOT;

    If I have the header name configured as : Vendor</br>Name
    then that is what is displayed.

    Now, the funny thing is that, as a test, I replaced all the spaces with "</br>" with str_replace and it worked.

    So now I created my own custom tag "~br~" that I us in the header configuration and just replace that with "</br>" and it works.

    $h_name = str_replace("~br~", "</br>", $h);
    $header .=<<<EOT
    <th>{$h_name}</th>
    EOT;

    I don't know exactly what is the difference between the string we read from the DB and the string we create with str_replace, because the end product has exactly the same characters as far as I can see.

    Weird, but it works

    Thanks

Sign In or Register to comment.