简体   繁体   中英

Bootstrap datatable not working on adding accordion

I have a datatable as follows:

foreach($tickets as $tickets)
{
    echo ('<tr>');
    echo ('<td>'.$tickets->error.'</td>');
    echo ('<td>'.$tickets->hours.'</td>');
    echo ('<td>'.$tickets->time.'</td>');
    echo ('<td>'.$tickets->date.'</td>');
    echo ('</tr>');
}

I added accordion effect to it likewise:

foreach($tickets as $tickets)
{
    echo ('<tr data-toggle="collapse" data-target=".demo1">');
    echo ('<td>'.$tickets->error.'</td>');
    echo ('<td>'.$tickets->hours.'</td>');
    echo ('<td>'.$tickets->time.'</td>');
    echo ('<td>'.$tickets->date.'</td>');
    echo ('</tr>');
    echo ('<tr>');
    echo ('<td class="hiddenRow">');
    echo ('<div class="collapse demo1">Demo1</div>');
    echo ('</td>');
    echo ('</tr>');
}

and the table has lost it's datatable properties such as search, view as 10/25/50 items per page etc.

在此处输入图片说明

Jquery:

$('.collapse').on('show.bs.collapse', function () {
    $('.collapse.in').collapse('hide');
});

$(".clickable-row").click(function() {
    window.location = $(this).data("href");
});

I'd like help regarding this issue.

尝试在第二个td上使用colspan =“ 4”

Here is fiddle: http://jsfiddle.net/3ghbLrpu/1/

<html>

  <head>

    <script src="js/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

  </head>

  <body>

    <table id="dataTable" class="table table-striped table-bordered" cellspacing="0" width="100%">
      <thead>
        <tr>
          <th>Error</th>
          <th>Time Spent</th>
          <th>Time</th>
          <th>Date</th>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <th>Error</th>
          <th>Time Spent</th>
          <th>Time</th>
          <th>Date</th>
        </tr>
      </tfoot>
      <tbody>
        <tr data-toggle="collapse" data-target=".demo1" class="accordion-toggle">
          <td>asd</td>
          <td>asd</td>
          <td>asd</td>
          <td>asd</td>
        </tr>
        <tr>
          <td class="hiddenRow" colspan="4">
            <div class="collapse demo1">Demo1</div>
          </td>
        </tr>
      </tbody>
    </table>

  </body>

CSS

.hiddenRow {
    padding: 0 !important;
}

Another option is use bootstrap and remove knockoutjs

https://codepen.io/creativedev/pen/XYMRyQ

$(document).ready(function() {
  $("#collapseme").click(function() {
    if($("#test").hasClass("out")) {
        $("#test").addClass("in");
        $("#test").removeClass("out");
    } else {
        $("#test").addClass("out");
        $("#test").removeClass("in");
    }
});
});

HTML

<table id="dataTable" class="table table-striped table-bordered" cellspacing="0" width="100%">
      <thead>
        <tr>
          <th>Error</th>
          <th>Time Spent</th>
          <th>Time</th>
          <th>Date</th>
        </tr>
      </thead>
      <tbody>
        <tr class="" id="collapseme">
          <td>asd</td>
          <td>asd</td>
          <td>asd</td>
          <td>asd</td>
        </tr>
        <tr>
          <td class="hiddenRow" colspan="4">
            <div class="collapse out" id="test">Demo1</div>
          </td>
        </tr>
  </tbody>

      <tfoot>
        <tr>
          <th>Error</th>
          <th>Time Spent</th>
          <th>Time</th>
          <th>Date</th>
        </tr>
      </tfoot>
    </table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM