简体   繁体   中英

jQuery dataTables tabletools not working

i am trying to use datatable table tools with the below config. I am not able to see table tool buttons that i have defined below. Am i missing something ? Please let me know.

var oTable = $('#dashboard').dataTable( { "bPaginate": true, "bLengthChange": false, "bFilter": true, "bSort": false, "bInfo": false, "bAutoWidth": false, "sPaginationType": "bootstrap", "aoColumnDefs": colHeaders,

                "oTableTools": {
                    "aButtons": [
                        {
                            "sExtends": "copy",
                            "sButtonText": "Copy to clipboard"
                        },
                        {
                            "sExtends": "csv",
                            "sButtonText": "Save to CSV"
                        },
                        {
                            "sExtends": "xls",
                            "sButtonText": "Save for Excel"
                        }
                    ]
                }
            });

set the sDom parameter

like this:

"sDom": 'T<"clear">lfrtip'

more info: http://datatables.net/release-datatables/extras/TableTools/index.html

Like @Dylan Slabbinck said, you have to set the "sDom" parameter, but you also have to set your "sSwfPath" in your project directory. Despite these changes combined with the code you've shown, it may not be enough. I would suggest you to initialize your table excluding the TableTools Buttons part and, after instantiating, set the buttons and their configuration.

"sDom": 'T<"clear">lfrtip' //inside your table configuration

TableTools.DEFAULTS.sSwfPath = "your path";
// mine was TableTools.DEFAULTS.sSwfPath = "<?php echo $this->basePath() ?>/swf/copy_csv_xls_pdf.swf";
TableTools.DEFAULTS.aButtons = ["xls", "copy", "csv"];
TableTools.BUTTONS.xls.sButtonText = "Save for Excel";
TableTools.BUTTONS.copy.sButtonText = "Copy to clipboard";
TableTools.BUTTONS.csv.sButtonText = "Save to CSV";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM