Trung Tran
Trung Tran

Reputation: 13721

HTML table won't fit inside of bootstrap panel

I am trying to fit a datatable inside of a bootstrap panel that's part of an accordion. However, the table keeps overflowing outside of the panel... could someone help? Here is my code:

<div class="container">
<div class="myaccordion">
    <div class="panel-group" id="accordion">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Section One</a>
                </h4>
            </div>
            <div id="collapseOne" class="panel-collapse collapse in">
                <div class="panel-body">
                    <div class="row"><!-- company orders -->
                      <div class="container">
                        <h3>{{context.company.company_name}}'s Orders</h3>
                        <table id="company_orders" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                              <thead>
                                  <tr>
                                    <th>Order Date</th>
                                      <th>Order ID</th>
                                      <th>PO #</th>
                                      <th>Order Total ($)</th>
                                      <th>Status</th>
                                      <th></th>
                                  </tr>
                              </thead>
                              <tbody>
                                  {{#each context.order}}
                                  <tr>
                                    <td class="order_date">{{order_date}}</td>
                                      <td class="order_id">{{order_id}}</td>
                                      <td class="po_num">{{po_num}}</td>
                                      <td class="order_total">{{order_total}}</td>
                                      <td class="price">{{order_status}}</td>
                                      <th><a href="/admin/{{order_id}}">View Details</a></th>
                                  </tr>
                                  {{/each}}
                              </tbody>
                          </table>
                      </div>
                    </div><!-- company orders end -->
                </div>
            </div>
        </div>
    </div>
</div>

Image showing table overflow on the right side

Upvotes: 1

Views: 2128

Answers (1)

max
max

Reputation: 8667

This is because you nested container in container. You can't do that in Bootstrap. Just use only row inside panel-body and col-md-12 class after row.

<div class="container">
  <div class="myaccordion">
    <div class="panel-group" id="accordion">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Section One</a>
            </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in">
      <div class="panel-body">
        <div class="row">
          <!-- company orders -->
          <div class="col-md-12">
            <h3>{{context.company.company_name}}'s Orders</h3>
            <table id="company_orders" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
              <thead>
                <tr>
                  <th>Order Date</th>
                  <th>Order ID</th>
                  <th>PO #</th>
                  <th>Order Total ($)</th>
                  <th>Status</th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                {{#each context.order}}
                <tr>
                  <td class="order_date">{{order_date}}</td>
                  <td class="order_id">{{order_id}}</td>
                  <td class="po_num">{{po_num}}</td>
                  <td class="order_total">{{order_total}}</td>
                  <td class="price">{{order_status}}</td>
                  <th><a href="/admin/{{order_id}}">View Details</a></th>
                </tr>
                {{/each}}
              </tbody>
            </table>
          </div>
        </div>
        <!-- company orders end -->
      </div>
    </div>
  </div>
</div>

Upvotes: 1

Related Questions