Jquery DataTable after adding scrolling function, Column footer does not align with its data column

Jquery DataTable after adding scrolling function, Column footer does not align with its data column

polachanpolachan Posts: 101Questions: 50Answers: 0

I am trying to show the table footer in the same column position of its data column along with its Vertical scrolling. Data table is showed with fixed column header. I am looking for some one help to fix the code. Now the footer is showed bit far from its data column. Here is my code

<div>
<table id="myTable" class="table table-bordered table-striped" style="width:100%;font-size:90%">
 <thead>
  <tr>
    <th>
       Item
    </th>
    <th>
       Net Value
    </th>
    <th>
       Total Value
    </th>
  </tr>
 </thead>
 <tbody>
   <tr>
      <td>AAA</td>
      <td>200.00</td>
      <td>300.00</td>
      <td>BBB</td>
      <td>300.00</td>
      <td>200.00</td>
   </tr>
 </tbody>
 <tfoot>
    <tr>
       <th>Total</th>
       <td>First Total</td>
       <td>Second Total</td>
    </tr>
</tfoot>
</table>
</div>
<script>
 $(document).ready(function () {
 var table = $('#myTable').DataTable({
     "pageLength": 40,
      scrollY: "500px",
      scrollCollapse: true,
      scrollX: true,
      paging: true,
      dom: 'Bfrtip',
      buttons: [
                { extend: 'copyHtml5', footer: true },
                { extend: 'excelHtml5', footer: true },
                { extend: 'csvHtml5', footer: true },
                { extend: 'pdfHtml5', footer: true }
            ]
 });
table.columns.adjust().draw();
})
</script>

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • allanallan Posts: 63,258Questions: 1Answers: 10,421 Site admin

    One think I just spotted what that your table header and footer have 3 columns, but the body has 6 columns. That should throw an error as your table does here: https://live.datatables.net/tidehufo/1/edit .

    Allan

Sign In or Register to comment.