我一直在努力导出我的数据表数据。 我尝试了以下链接,其中提到了一些代码但在我的情况下,我什么都没得到。 链接:http://datatables.net/extras/tabletools/
我的代码:
$(document).ready(function () {
$("#btnGuru").click(function () {
tableToExcel('myDataTable', 'W3C Example Table');
});
$.datepicker.regional[""].dateFormat = 'dd/mm/yy';
$.datepicker.setDefaults($.datepicker.regional['']);
debugger;
var dt = $('#myDataTable').dataTable({
"sDom": 'T<"H"plfr>t<"F"ip>',
"oTableTools": {
"aButtons": [ "csv", "pdf" ],
"sSwfPath": "https://datatables.net/release-datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf"
},
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "Home/AjaxHandler",
"bJQueryUI": true,
"aoColumns": [
{
"sName": "Lead_Id",
"bVisible": false,
"bSearchable": false,
"bSortable": false
},
{
"sName": "Contact_Name" ,
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href=\"Home/Details/' + oObj.aData[0] + '\">' + oObj.aData[1] + '</a>';
}
},
{ "sName": "Contact_Address" },
{ "sName": "Lead_Source" },
{ "sName": "Domain" }
]
});
此致
答案 0 :(得分:1)
强烈建议您在项目内的本地目录中包含“sSwfPath”文件。我建议你下载它们。另外,我认为“sDom”也应该有所不同(查看你自己发布的链接)。
我的建议是你将表格初始化为“sDom”并稍后初始化表格工具。最后但同样重要的是,最后将本地源添加到swf。
var dt = $('#myDataTable').dataTable({
"dom": 'T<"clear">lfrtip',
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "Home/AjaxHandler",
"bJQueryUI": true,
"aoColumns": [
{
"sName": "Lead_Id",
"bVisible": false,
"bSearchable": false,
"bSortable": false
},
{
"sName": "Contact_Name" ,
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href=\"Home/Details/' + oObj.aData[0] + '\">' + oObj.aData[1] + '</a>';
}
},
{ "sName": "Contact_Address" },
{ "sName": "Lead_Source" },
{ "sName": "Domain" }
]
});
TableTools.DEFAULTS.aButtons = [ "csv", "pdf" ];
TableTools.DEFAULTS.sSwfPath = your path here!
// this is the way I did it
//TableTools.DEFAULTS.sSwfPath = "<?php echo $this->basePath() ?>/swf/copy_csv_xls_pdf.swf";
试试这个。