2014-03-05 32 views
0

我顯示了數年後的統計數據。瞭解帶數據表的列

我使用JavaScript編寫的DataTables。

我在選擇標籤中選擇了一年,我的應用程序顯示自今年以來的統計數據。

第一選擇一年的工作很好,但我選擇了第二年,我有這樣的:

首先選擇(2005年),它工作得很好:

enter image description here

的第二選擇(2011年),顯示一些列太:

enter image description here

THRID選擇(2004年),失蹤最後一欄標題:

enter image description here

這裏是我的JavaScript代碼:

function showStatistic11() { 
$("#contentCamp").empty(); 
$.ajax({ 
    url: 'Statistic_11.html', 
    dataType: 'html', 
    success: function (data) { 
     $("#contentCamp").html(data); 
     getStatistic11(); 
    }, 
    error: function (e) { 
     alert("Error loading statistic 11 html : " + e.statusText); 
    } 
}); 
} 

function getStatistic11() { 

var response; 
var allstat11 = []; 
var allyearstat11 = []; 
var currentYear = new Date().getFullYear(); 
var nbY = $('#Select1').val(); 

if (nbY) {//first time empty 
    nbY = currentYear - nbY; 
    $.ajax({ 
     type: 'GET', 
     url: 'http://localhost:52251/Service1.asmx/Statistic_11', 
     data: { "nbYear": nbY }, 
     contentType: 'application/json; charset=utf-8', 
     dataType: 'json', 
     success: function (msg) { 
      response = msg.d; 
      for (var i = 0; i < response.Items.length; i++) { 
       allstat11[i] = new Array(nbY); 
       var j = 0; 
       allstat11[i][j] = response.Items[i].Interventie; 
       var t = 1; 
       while (j <= nbY) { 

        allstat11[i][t] = response.Items[i].Sum[j]; 
        t++; 
        j++; 
       } 
      } 

      allyearstat11[0] = ""; 
      var n = 1; 
      for (var k = 0; k <= nbY; k++) { 

       allyearstat11[n] = response.Items[0].YearStart + k; 
       n++; 
      } 
      fillDataTable11(allstat11, allyearstat11); 
      $('table').visualize({ type: 'line' }); 

     }, 
     error: function (e) { 
      alert("error loading statistic 11"); 
     } 
    }); 
} 
} 

function fillDataTable11(data, allyearstat11) { 

if ($("#table_statistic_11").css("visibility") == "hidden") 
    $("#table_statistic_11").css("visibility", "visible"); 

var tabTitreColonne = []; 

for (var i = 0; i < allyearstat11.length; i++) { 
    tabTitreColonne.push({ 
     "sTitle": allyearstat11[i], 
    }); 
}; 

$('#table_statistic_11').dataTable({ 

    'aaData': data, 
    'aoColumns': tabTitreColonne, 
    "iDisplayLength": 12, 
    "bJQueryUI": true, 
    "bDestroy": true, 
    "bPaginate": false, 
    "bLengthChange": false, 
    "bFilter": false, 
    "bSort": false, 
    "bInfo": false, 
    "bAutoWidth": false 
}); 
} 

有沒有用我的數據表(bDestroy,bFilter,bAutoWidth ...)的caracteristic一個問題嗎? 有什麼問題?

回答

0

我解決了這個問題,在填充DataTable之前,我將我的theadtbody標籤清空到每個新的負載。

代碼:

$('thead').html(""); 
$('tbody').html("");