首先绘制的数据表没有得到计数数据

时间:2018-04-05 07:38:05

标签: jquery datatable

我的数据表有问题, 这是我的代码

var table = $('#reportpr');
        var target = table.attr('data-table');
        var tblDetail = table.attr('data-detail');
        var oTable = table.on( 'processing.dt', function ( e, settings, processing ){
            if (processing) {
                $(this).find('tbody').addClass('load1 csspinner');
            } else{
                $(this).find('tbody').removeClass('load1 csspinner');
            };
        }).DataTable({
            "bServerSide": true,
            "dom": 'Bfrtip',
            "buttons": [
                'excelHtml5'
            ],
            "scrollX": true,
            "scrollY":        "200px",
            "scrollCollapse": true,
            "iDisplayLength": 10,
            "ajax": {
                "url" : url+"datatable",
                "type": "POST",
                "data" :{
                           judul: target
                        },
            }                
        });

        $('#search').click(function() {
            console.log($("#reportpr").DataTable().data().count());             

            var typepo = $('input[name=typepo]:checked').val();
            var sform = $('#sform').val();
            var sto = $('#sto').val();
            var buyer = $('#buyer').val();
            var country = $('#country').val();
            var vendor = $('#vendor').val();        
            var opt = $('#opt').val();              
            var optval = $('#optval').val();    
            var startDate = new Date(sform);
            var endDate   = new Date(sto);

            var endMoment   = moment(endDate);
            var startMoment = moment(startDate);
            //console.log(jum);
             //[days, years, months, seconds, ...]
            //console.log(endMoment.diff(startMoment, 'months')<4);

            //var dataString ="judul=" + target + "&typepo=" + typepo + "&sform=" + sform + "&sto=" + sto + "&buyer=" + buyer + "&country=" + country + "&vendor=" + vendor + "&opt=" + opt + "&optval=" + optval;
            if($("#form-filter-pr").valid()==true)
            {
                if(endMoment.diff(startMoment, 'months')<4)
                {
                    //console.log(oTable);
                    oTable.ajax.url( url+'datatable/'+target+'?typepo=' + typepo + "&sform=" + sform + "&sto=" + sto + "&buyer=" + buyer + "&country=" + country + "&vendor=" + vendor + "&opt=" + opt + "&optval=" + optval).load();
                }
                else
                {
                    swal("The date period is too large", "Please input a minimum 3 month period", "warning");
                }
            }


        });

我的问题是,当我第一次重新加载我的ajax时,数据显示但在console.log($("#reportpr").DataTable().data().count());中显示为0.当我再次尝试重新加载我的ajax时(第二次)它显示300.我的问题是为什么我第一次没有得到数据?我有什么想念吗?

0 个答案:

没有答案