数据表+如何将服务器端处理代码与文件导出代码相结合 [英] datatables + how to combine server side processing code with File export code
问题描述
这是一个添加按钮以将数据导出到csv,pdf,excel的数据表示例。
This is a datatables example of adding buttons to export data to csv, pdf, excel.... fiddle here
https://datatables.net/extensions/buttons/examples/initialisation/export.html
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
} );
} );
这是服务器端处理的数据表示例
This is a datatables example of Server-side processing
https://datatables.net/examples/server_side/simple.html
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "scripts/server_processing.php"
} );
} );
现在我如何将上面的代码组合成一个,所以我有一个数据表,服务器这是我的尝试,但我不知道哪里是错的,或者如果我真的很近。
Now how do I combine the above code into one, so that i have a data tables that does server side processing and that this is my attempt, but I am not sure where it is wrong, or if indeed I am close.
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "scripts/server_processing.php",
"dom": 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
} );
} );
我已经尝试过各种排列,但是我仍然在控制台中出现错误未知的语法错误:意外的字符串
任何人都可以建议?
I have tried various permutations but I am still getting an error in the console Uncaught SyntaxError: Unexpected string
Can anyone advise?
这是我正在使用
$(document).ready(function() {
var dataTable = $('#employee-grid').DataTable( {
"processing": true,
"serverSide": true,
"ajax":{
url :"employee-grid-data2.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server -- startagain1-index2.php </th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
},
"dom:" 'Bfrtip',
"buttons": [
'copy', 'csv', 'excel', 'pdf', 'print'
]
} );
} );
推荐答案
您有sintax错误,请更改此行中的代码:
You have sintax error, change your code in this line:
"dom:" 'Bfrtip', //incorrect
"dom" : 'Bfrtip', //correct
结果: https://jsfiddle.net/cmedina/7kfmyw6x/42/
这篇关于数据表+如何将服务器端处理代码与文件导出代码相结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!