Beauvais
Beauvais

Reputation: 2279

Force each row in Bootstrap table to be a one-liner when table is wider than screen

I am building up a dynamic table which consists of 1-50 columns depending what the user selects. When the user selects 1-6 colums there is no problem showing all the data on the screen but when the user selects more than 6 columns the table tries to squeeze the view together on the screen resulting in each row being expanded to multiple lines.

I want it to always show the text in one line as this (OK): OK

But having many columns will wrap the text in to two or more lines (not OK): Not OK

The column width is not defined as it also varies depending on the text to show.

How can I make sure the row will always be a one-liner like ex.1 no matter how many columns the user selects?

I have this JSFiddle demo with the code for the two above examples:

<table class='table'>
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
            <th>Column 3</th>
            <th>Column 4</th>
            <th>Column 5</th>
            <th>Column 6</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Row 1</td>
            <td>Row 11</td>
            <td>Row 11 1</td>
            <td>Row 11 11</td>
            <td>Row 11 11 1</td>
            <td>Row 11 11 11</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 22</td>
            <td>Row 22 2</td>
            <td>Row 22 22</td>
            <td>Row 22 22 2</td>
            <td>Row 22 22 22</td>
        </tr>
    </tbody>
</table>

Upvotes: 19

Views: 16540

Answers (1)

radomaj
radomaj

Reputation: 871

Try adding this css to your table elements: white-space: nowrap jsFiddle

Upvotes: 44

Related Questions