html - 使用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 -->
解决方案
推荐阅读
- javascript - 有没有办法在 Javascript 中添加链接(包含 php)?
- python - 第一个路由过滤器后的路由
- c++ - 在 C++ 类中实现 TPCircularBuffer
- android - 使用 Xamarin 将文件写入手机的内部存储
- oop - 如何在 UML 类图中对非成员聚合建模
- javascript - 元素。删除不起作用。(innerHTML 工作正确)
- python - TypeError:强制转换为 Unicode:需要找到字符串或缓冲区日期时间日期时间
- excel - 使用 excel 宏将订单添加到主库存
- java - 带接口的 Spring 目录结构(最佳实践)
- ios - 呼叫未连接时如何关闭 Callkit UI