在数据表函数中追加一个对象
Append an object inside the datatable function
需要在数据表函数中附加一个对象。我在我的应用程序的多个页面中有以下代码。我试图从整个应用程序的公共 JS 文件向此函数附加一个对象。
var table;
$(document).ready(function() {
table = $('#table').DataTable({
dom: 'lBfrtip',
lengthMenu: [
[ 10, 25, 50, 100, -1 ],
[ '10', '25', '50', 100, 'Show all' ]
],
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"columnDefs": [
{
"targets": [ -1 ], //last column
"orderable": false, //set not orderable
},
],
});
});
我尝试将按钮 属性 推到通用 JS 文件中的 DataTable 函数,如下所示:
table.push({buttons: [
{
text:'Save as PDF',
className: "btn btn-primary",
extend: 'pdfHtml5',
download: 'open',
}
]
});
但是出现这个错误:
Uncaught TypeError: Cannot read properties of undefined (reading 'push')
尝试将按钮添加到 dataTable.defaults
对象:
$.extend(true, $.fn.dataTable.defaults, {
buttons: [
{
text:'Save as PDF',
className: "btn btn-primary",
extend: 'pdfHtml5',
download: 'open'
}
]
});
需要在数据表函数中附加一个对象。我在我的应用程序的多个页面中有以下代码。我试图从整个应用程序的公共 JS 文件向此函数附加一个对象。
var table;
$(document).ready(function() {
table = $('#table').DataTable({
dom: 'lBfrtip',
lengthMenu: [
[ 10, 25, 50, 100, -1 ],
[ '10', '25', '50', 100, 'Show all' ]
],
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"columnDefs": [
{
"targets": [ -1 ], //last column
"orderable": false, //set not orderable
},
],
});
});
我尝试将按钮 属性 推到通用 JS 文件中的 DataTable 函数,如下所示:
table.push({buttons: [
{
text:'Save as PDF',
className: "btn btn-primary",
extend: 'pdfHtml5',
download: 'open',
}
]
});
但是出现这个错误:
Uncaught TypeError: Cannot read properties of undefined (reading 'push')
尝试将按钮添加到 dataTable.defaults
对象:
$.extend(true, $.fn.dataTable.defaults, {
buttons: [
{
text:'Save as PDF',
className: "btn btn-primary",
extend: 'pdfHtml5',
download: 'open'
}
]
});