2010-07-06 48 views
0

我有一個問題,我試圖做一個表使用數據表...我已經從datatable.net下載.. 但數據網格不顯示.. 。只是表頭(thead)... 哪裏是我的錯?製作數據表的麻煩,初始化後<tbody>仍然是空的

<table cellpadding="0" cellspacing="0" border="0" class="display" id="datalist"> 
     <thead> 
      <tr> 
       <th>Line </th> 
       <th>Model </th> 
       <th>Serial </th> 
       <th>NIK </th> 
      </tr> 
     </thead> 
     <tbody> </tbody> 
</table> 

<script> 
$(document).ready(function(){ 
     var oTable; 
     oTable = $("#datalist").dataTable({ 
      "bRetrieve" : true, 
      "bServerSide": true, 
      "bProcessing": true, 
      "sAjaxSource": 'showlist.php', 
      "aaSorting" : [[1,"desc"]], 
      "aoColumns" : [ 
          /*Line*/ null, 
          /*Model*/ null, 
          /*Serial*/null, 
          /*NIK*/ null 
          ] 
      }); 
     }); 
</script> 

在螢火沒有顯示錯誤,並在後的反應顯示結果:

{"aaData":[ 
       ["FA 04","KW-XC555UD","123X0098","12345"], 
       ["FA 05","KD-R435UHD","113X0057","12345"], 
       ["FA 11","kd-r411uhd","115x0021","12345"], 
       ["FA 04","kw-xc406hund","105x1101","12345"], 
       ]}   
+2

請代碼!....你不是新手,你知道,我們不能說「哦,你的錯在那裏!」,當我們什麼都不能指向時...... – Reigel 2010-07-06 07:09:37

+0

對不起,我遲到了發佈我的代碼.. – klox 2010-07-06 07:13:16

+0

你使用這個嗎?http://datatables.net/examples/server_side/server_side.html如果是的話,請嘗試檢查螢火蟲如果'showlist.php '返回的東西...... – Reigel 2010-07-06 07:17:00

回答

0

我一直在使用這種代碼:

$rResultTotal = mysql_query($sQuery) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error()); // submit SQL to MySQL an$ 
     $aResultTotal = mysql_fetch_array($rResultTotal); 
     $iTotal = $aResultTotal[0]; 

     $sOutput = '{'; 
     $sOutput .= '"sEcho": '.intval($_POST['sEcho']).', '; 
     $sOutput .= '"iTotalRecords": '.$iTotal.', '; 
     $sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', '; 
     $sOutput .= '"aaData": [ '; 
     while ($aRow = mysql_fetch_array($rResult)) 
     { 
       $sOutput .= "["; 
       $sOutput .= '"'.addslashes($aRow['Line']).'",'; 
       $sOutput .= '"'.addslashes($aRow['Model']).'",'; 
       $sOutput .= '"'.addslashes($aRow['Serial_number']).'",'; 
       $sOutput .= '"'.addslashes($aRow['NIK']).'"'; 
       $sOutput .= "],"; 
     } 
     $sOutput = substr_replace($sOutput, "", -1); 
     $sOutput .= '] }'; 

     echo $sOutput; 
0

我看XHR返回的值(of the sample),它原來有這樣的模式,

{"sEcho": 1, "iTotalRecords": 57, "iTotalDisplayRecords": 57, "aaData": [ ["Gecko", .... 

嘗試在你的,讓看看它是否修復它...

+0

這是代碼放在showlist.php? – klox 2010-07-06 07:46:06

+0

JSON是示例頁面在PHP中返回的內容......您的showlist.php也必須返回類似的內容......您可以在http://datatables.net/examples/server_side/server_side看到如何做到這一點。 html – Reigel 2010-07-06 07:58:14

0

我有類似的問題,並通過這種方式決定了它:

  1. 從這個網站(http://datatables.net)下載數據表-1.7的新版本; 如果這不會幫助 -
  2. 嘗試查看您試圖使用數據表的數據庫表中的數據。用數據庫操縱 。如果某些單元格中的數據末尾有任何錯誤符號(如段落符號等),請注意記錄。如果有的話 - 嘗試從數據中刪除它們。然後它必須工作。祝你好運。
+1

有時在下載數據文件變得損壞後,我使用「1.6」。之後,我重新下載了文件。我的項目可以正常工作。 – klox 2010-08-21 09:58:58

相關問題