DataTable服务器端脚本,用于导出所有filterered数据

时间:2015-08-19 11:21:42

标签: php codeigniter datatable datatables

我正在使用数据表服务器端脚本从表中获取数据。我在数据库表中有500 000条记录。我想使用datatable tableTool插件导出所有500,000条记录。现在我能够以分页限制导出当前页面数据。

var otable = $('#datatable_fixed_column').DataTable({           
        "bProcessing": true,
        "serverSide":true,          
                 "ajax": "index.php?c=datadownload&m=getalldata",
        "sDom": ""+
                "<'dt-toolbar'<'col-xs-12 col-sm-6'l><'col-sm-6 col-xs-6 hidden-xs'T>>"+
                "t"+
                "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-sm-6 col-xs-12'p>>",

        "oTableTools": {
             "aButtons": [
                {
                    "sExtends": "copy",
                    "mColumns": [0,1,2],
                    "oSelectorOpts": {filter: 'applied', order: "current"}
                },             

               {
            "sExtends": "csv",
                    "mColumns": [0,1,2],
                    "sTitle":"Category Data",
                    "oSelectorOpts": {filter: 'applied'},

                },

                {
                    "sExtends": "xls",
                    "mColumns": [0,1,2],
                    "sFileName":"*.xls",
                    "sTitle":"Category Data",
                    "oSelectorOpts": {filter: 'applied', order: "current" }
                },             

             ],
            "sSwfPath": baseUrl+"public/plugins/datatables/swf/copy_csv_xls_pdf.swf"
        },
        "aoColumns":[


            {
                "mData":"data1",
                "sName":"data1",
                "sTitle":"data1"

            },
            {
                "mData":"data2",
                "sName":"data2",
                "sTitle":"data2"
            },
                 {
                        "mData":"data3",
                        "sName":"data3",
                        "sTitle":"data3"
                 }





        ],
        "autoWidth" : true

    });     

2 个答案:

答案 0 :(得分:0)

http://legacy.datatables.net/ref

//How many results to show per page, set this to enough to show them all then export 

"aLengthMenu": [[10, 25, 50, 100, 500, 1000], [10, 25, 50, 100, 500, 1000]]

答案 1 :(得分:0)

您可以适当使用lengthMenu。

允许无限数量的记录 可以使用长度菜单指定function getMAC() { var mac = null; try { mac = webapis.network.getMac(); } catch (e) { addResult("getMAC exception [" + e.code + "] name: " + e.name + " message: " + e.message); } if (null != mac) { addResult("[getMAC] mac: " + mac); } } Limit -1

Limit null

"lengthMenu" : [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]]

另一种方法是使用尽可能高的int / bigint值。

"lengthMenu" : [[10, 25, 50, 100, null], [10, 25, 50, 100, "All"]]