javascript - datatable scrollX 在动态列中无法正常工作
问题描述
我正在尝试从geojson feature.properties
模态中动态显示很多列。我已成功显示它,但问题是当我单击下一页时,scrollX 没有按预期工作。
这是我的代码:
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document" style="margin:auto !important;max-width:1080px !important;">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Map Attributes</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="modalbody_1">
<div class="">
<table id="mapattr" class="display nowrap" style="width:100%" cellspacing="0">
<thead></thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
var dataGSet = [];
var dataGArray;
var columnRef = [];
$.get(url, function(data) {
columnRef = [];
$("#mapattr > thead").append("<tr></tr>");
$.each(data.features, function(a, b) {
var cRow = [];
$.each(b.properties, function(key, value) {
if (a == 0) {
$("#mapattr > thead > tr").append("<td>" + key + "</td>");
columnRef.push({
title: key
})
}
cRow.push(value);
});
dataGSet.push(cRow);
});
}).done(function() {
dataGArray = JSON.parse(JSON.stringify(dataGSet));
if (!$.fn.DataTable.isDataTable('#mapattr')) {
$("#mapattr").DataTable({
dom: 'Bfrtip',
data: dataGArray,
scrollX: true,
buttons: [
'copy', 'csv', 'excel', 'pdf'
]
});
} else {
$('#mapattr').DataTable().destroy();
$('#mapattr').empty();
$("#mapattr").DataTable({
dom: 'Bfrtip',
data: dataGArray,
scrollX: true,
buttons: [
'copy', 'csv', 'excel', 'pdf'
]
});
}
});
</script>
我已经尝试了这篇文章table-responsive
的建议,但是用户滚动它的问题,按钮、页面和搜索框也会滚动,所以当客户想要在另一个页面中导航时,这对客户来说有点麻烦。
解决方案
推荐阅读
- python - 无法在下面的 python 代码中进行插入排序工作
- javascript - 将锚标记添加到手风琴
- javascript - 如何在页面中的跨域框架上执行鼠标移动事件并读取与该元素相关的数据?
- java - 如何在运行时在方法上添加 Java 注释
- ios - 如何检查弹出文本字段中的文本是否在严格的数字范围内
- php - AJAX 不返回对象
- c++ - std::string 的 c_str() 函数如何返回空终止字符串?
- angular - Angular 4.3 - 如何删除 HttpParams 中的参数
- html - 如何在不破坏 CSS 对齐的情况下修复文本换行?
- c# - 如何从参数创建“公共字符串数组”作为数组?