如何在TableTools中使用链接而不是flash按钮

我正试图找到一种方法来改变TableTools上的按钮。 我想使用自己的自定义链接而不是闪光按钮。 有没有办法可以做到这一点? 任何好的资源教我如何进行修改,仍然能够使用按钮收集等function。

根据创建者的说法,获取TableTools导出function的唯一方法是使用Flash按钮。

您找到的其他线程应该说当前,不,这不是TableTools提供的选项。 Flash选项用于提供跨浏览器/平台的能力,以完全在客户端保存文件 – 该选项在旧版浏览器(IE6,IE7等)中不可用,其中不支持data://协议和本地文件系统交互选项。

肯定有可能将这种能力添加到TableTools,但我担心我还没有机会这样做。 虽然它在路线图上。

艾伦

如果您对创建导出文件服务器端感兴趣,可能需要考虑TableTools 的下载(GET)插件 。

是的,可以覆盖现有按钮,例如PDF / CSV等,或者创建新的自定义按钮,这些按钮具有指向URL的链接以获取或发布数据。 在这里,我用get方法显示了两个方法:

有关Get&Post方法的更多信息:

访问: Datatable tabletools GET / POST下载方法覆盖

使用代码生成的pdf是因为具有按某些列数据分组的行的表上的tabletools的pdf输出是重叠的。

第1次覆盖PDFfunction和

第二个创建自定义按钮。

1.覆盖PDF函数以从服务器代码中获取pdf。

/*Get Method table Tools - PDF - Overriding*/ TableTools.BUTTONS.pdf = { "sAction": "text", "sTag": "default", "sFieldBoundary": "", "sFieldSeperator": "\t", "sNewLine": "
", "sToolTip": "", "sButtonClass": "DTTT_button_text", "sButtonClassHover": "DTTT_button_text_hover", //"sButtonText": "PDF", "mColumns": "all", "bHeader": true, "bFooter": true, "sDiv": "", "fnMouseover": null, "fnMouseout": null, "fnClick": function (nButton, oConfig) { var oParams = this.s.dt.oApi._fnAjaxParameters(this.s.dt); var iframe = document.createElement('iframe'); iframe.style.height = "0px"; iframe.style.width = "0px"; //iframe.src = oConfig.sUrl + "?" + $.param(oParams); iframe.src = oConfig.sUrl;//This is the URl you give in datatable Tabletools pdf override below document.body.appendChild(iframe); }, "fnSelect": null, "fnComplete": null, "fnInit": null }; /**/ /*Datatable initialisation*/ $(document).ready(function () { oTable = $('#alternatecolor').dataTable({ "bJQueryUI": true, "aLengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ], "sPaginationType": "full_numbers", "aoColumns": [ null, null, null, null, null], "bLengthChange": false, "bPaginate": false, "sDom": '<"H"Tfr>t<"F"ip>', //"sDom": 'T<"clear">lfrtip', "oTableTools": { "aButtons": [ "csv", "xls", { /*PDF Override*/ "sExtends": "pdf", "sButtonText": "PDF", //Custom url to fetch pdf report "sUrl": " report/PDFReportUsers/us/1" } ] } }) /*Row grouping - optional*/ .rowGrouping({ bExpandableGrouping: true, bExpandSingleGroup: false, iExpandGroupOffset: -1 //asExpandedGroups: [name] }); /**/ }); });

2.自定义按钮,用于从服务器代码中获取pdf。

  /*Get Method table Tools - Download custom button*/ TableTools.BUTTONS.download= { "sAction": "text", "sTag": "default", "sFieldBoundary": "", "sFieldSeperator": "\t", "sNewLine": "
", "sToolTip": "", "sButtonClass": "DTTT_button_text", "sButtonClassHover": "DTTT_button_text_hover", //"sButtonText": "PDF", "mColumns": "all", "bHeader": true, "bFooter": true, "sDiv": "", "fnMouseover": null, "fnMouseout": null, "fnClick": function (nButton, oConfig) { var oParams = this.s.dt.oApi._fnAjaxParameters(this.s.dt); var iframe = document.createElement('iframe'); iframe.style.height = "0px"; iframe.style.width = "0px"; //iframe.src = oConfig.sUrl + "?" + $.param(oParams); iframe.src = oConfig.sUrl; document.body.appendChild(iframe); }, "fnSelect": null, "fnComplete": null, "fnInit": null }; /**/ $(document).ready(function () { oTable = $('#alternatecolor').dataTable({ "bJQueryUI": true, "aLengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ], "sPaginationType": "full_numbers", "aoColumns": [ null, null, null, null, null], "bLengthChange": false, "bPaginate": false, "sDom": '<"H"Tfr>t<"F"ip>', //"sDom": 'T<"clear">lfrtip', "oTableTools": { "aButtons": [ "csv", "xls" , { "sExtends": "download", "sButtonText": "Download PDF", "sUrl": "admin/user/4/downloadfile" } ] } }) /*Row grouping - optional */ .rowGrouping({ bExpandableGrouping: true, bExpandSingleGroup: false, iExpandGroupOffset: -1 //asExpandedGroups: [name] }); /**/ });