How to export all rows from Datatables using Ajax?

前端 未结 12 1174
广开言路
广开言路 2020-11-29 23:38

I am using new feature in Datatables: \"HTML5 export buttons\". I am loading data with Ajax.

https://datatables.net/extensions/buttons/examples/html5/simple.html

12条回答
  •  北海茫月
    2020-11-29 23:57

    you can make a hidden extra table in your page then make a button for download all data , assign this code for make hidden table as datatable with all rows with these options

    var options = {
                "processing": true,
                "serverSide": true,
                "ajax": fullbase,
                "language": {
                    "search": "Buscar: ",
                    "zeroRecords": "Datos no encontrados."
                },
                "initComplete": function(settings, json) {
                    $(".buttons-excel").click();
                },
                "iDisplayLength": 100000,
                lengthMenu: [[10,25,50,100, 100000], [10,25,50, 100, "All"]],
                "buttons": [{
                    extend : 'excel',
                    exportOptions : {
                            order : 'current',  
                            page : 'all',    
                            search : 'none' 
                    }
                }],
                "dom": "Blfrtip",
            };
    

    you can see a trigger on export excel button in complete table event and will run automatically for user when user click on that button then get an excel with all data

提交回复
热议问题