Datatable服务器端导出仅捕获第一页

时间:2018-11-21 01:22:04

标签: php jquery datatable

下面是我的脚本。我正在使用自定义过滤器日期时间范围。第一次加载它将加载空数据,因为我想避免在打开此页面时加载数据,直到我们对其进行过滤,只有它才会显示过滤后的数据。但是导出内容似乎只占用了数据表的第一页。例如,过滤后加载了400行数据,并以excel格式导出时,它将占用10行数据,而不是400行。

$(document).ready(function() {
        $('#datetimepicker').datetimepicker({
            format: 'yyyy-mm-dd HH:mm:ss'
        });


        $('#datetimepicker1').datetimepicker({
            format: 'yyyy-mm-dd HH:mm:ss'
        });

        fetch_data('no');

        var buttonCommon = 
        {
            exportOptions: 
            {
                modifier: {
                    page: 'all'
                },
                format: {
                    body: function ( data, row, column, node ) 
                    {
                        return column === 10 ?
                            data.replace( /[$,]/g, '' ) :
                            data;
                    }
                }
            }
        };

        function fetch_data(is_date_search, datetimepicker='', datetimepicker1='')
        {
        var dataTable = $('#demo-custom-toolbar').DataTable( {
            "responsive": true,
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"read.php", // json datasource
                type: "post", 
                data:{
                    is_date_search:is_date_search, datetimepicker:datetimepicker, datetimepicker1:datetimepicker1
                },
                // method  , by default get
                error: function()
                {  // error handling
                    $(".employee-grid-error").html("");
                    $("#demo-custom-toolbar").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
                    $("#employee-grid_processing").css("display","none");

                }
            },
            rowReorder: {
            selector: 'td:nth-child(2)'
            },
            responsive: true,
            dom: 'lBfrtip',
            buttons: [
                $.extend( true, {}, buttonCommon, {
                    extend: 'copyHtml5'
                } ),
                $.extend( true, {}, buttonCommon, {
                    extend: 'excelHtml5'
                } ),
                $.extend( true, {}, buttonCommon, {
                    extend: 'pdfHtml5'
                } )

            ]
        } );

    }

    //$("#employee-grid_filter").css("display","none");  // hiding global search box

        $('#search').click(function(){
            var start_date = $('.datetimepicker').val();
            var end_date = $('.datetimepicker1').val();

            if(start_date !='' && end_date !='')
            {
                $('#demo-custom-toolbar').DataTable().destroy();
                fetch_data('yes', start_date, end_date);
            }
            else
            {
                alert("Both Date is Required");
            }
        });

    } );

我试图将其放在下面的代码中,但效果也不佳。

exportOptions: {
    modifier: {
        page: 'current'
    }
},

0 个答案:

没有答案