我试图在Datatable中的data中显示数据,并允许用户以所需格式下载。但它似乎不起作用,我的数据既不能显示也不能下载。这是我目前使用的代码。
document.addEventListener("DOMContentLoaded", function(event) {
var dTable=$('#ex-table').DataTable({
"bDestroy": true,
dom: 'lfrtipB',
buttons: [
{
extend: 'copyHtml5',
title: 'Records'
},
{
extend: 'csvHtml5',
title: 'Records'
},
{
extend: 'excelHtml5',
title: 'Records'
},
{
extend: 'pdfHtml5',
title: 'Records'
},
'print'
],
lengthMenu: [[5, 20, 50, -1], [5, 20, 50, "All"]]
});
});
var databaseRef = firebase.database().ref("users/");
var table = $('#ex-table').DataTable();
databaseRef.on("child_added", function(data) {
var storageObj = data.val();
var dataSet = [storageObj.Department, storageObj.EmpId, storageObj.Name, storageObj.Position];
table.rows.add([dataSet]).draw();
});
https://codepen.io/jagrutitiwari/pen/WYBWVy
对于我正在尝试的代码。我哪里做错了?
更新:
users
节点:
更新2
安全规则:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
更新3
如果我加上
dataSrc
到Datatable它可以工作,但我现在看不到Datatable中的导出按钮。
document.addEventListener("DOMContentLoaded", function(event) {
var dTable=$('#ex-table').DataTable({
"bDestroy": true,
dom: 'lfrtipB',
data: dataSrc,
buttons: [
{
extend: 'copyHtml5',
title: 'Records'
},
{
extend: 'csvHtml5',
title: 'Records'
},
{
extend: 'excelHtml5',
title: 'Records'
},
{
extend: 'pdfHtml5',
title: 'Records'
},
'print'
],
lengthMenu: [[5, 20, 50, -1], [5, 20, 50, "All"]]
});
});