首页 > 解决方案 > 使用jquery将数据动态附加到表中,下载时只会得到一行

问题描述

这是我的 .gohtml 页面。我正在尝试合并引导主题(最小管理员)。请指导如何使用它。如果有人有它的文档,请参考。在这里,我尝试将它的数据表与“导出到 excel,pdf”功能一起使用。它被导出到excel,但只有一行表格被复制而不是整个表格。我尝试了很多但无法解决。请帮助!

代码如下

$(document).ready(function() {
  $.get("/norm/Pune/2021-08-02", function(data) {
    if (!data) {
      return
    }
    
    var table = document.getElementById('datatable-buttons')

    for (var i = 0; i < data.length; i++) {
      var row = `<tr>
                     <td>${data[i].date}</td>
                     <td>${data[i].location}</td>
                      <td>${data[i].Part_number}</td>
                      <td>${data[i].Norm}</td>
                      <td>${data[i].Item_category}</td>
                        </tr>`

      table.innerHTML += row
    } //for
  });
})
#datatable-buttons {
  border-collapse: collapse; 
  border-spacing: 0; 
  width: 100%;
}
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

<div class="row">
  <div class="col-12">
    <div class="card">
      <div class="card-body">

        <h4 class="card-title">Buttons example</h4>
        <p class="card-title-desc">The Buttons extension for DataTables provides a common set of options, API methods and styling to display buttons on a page that will interact with a DataTable. The core library provides the based framework upon which plug-ins can built.
        </p>

        <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap">
          <thead>
            <th>Date</th>
            <th>Location</th>
            <th>Part Number</th>
            <th>Norm</th>
            <th>Item Category</th>
          </thead>
        </table>

      </div>
    </div>
  </div>
  <!-- end col -->
</div>
<!-- end row -->

标签: htmljquery

解决方案


推荐阅读