Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 309
Beauvais Avatar asked Mar 10 '14 07:03

Beauvais


People also ask

How do I set the width of a bootstrap table?

If you're using <table class="table"> on your table, Bootstrap's table class adds a width of 100% to the table. You need to change the width to auto. Also, if the first row of your table is a header row, you might need to add the width to th rather than td.

How do you fix a column width in a table?

The width of the columns i.e. td in a table can be fixed very easily. This can be done by adding the width attribute in the <td> tag. If the width is not specified, the width of the column changes according to the change in the content. The specifications of width for the columns can be in pixels, or percentage.

What makes bootstrap striped table?

table-stripped class is used to create an alternate dark and light rows. Use the combination of table and table-stripped classes within the <table> tag to create a striped table. Example: HTML.


1 Answers

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

like image 73
radomaj Avatar answered Oct 19 '22 03:10

radomaj