2016-01-31 24 views
2

我有問題在jQuery DataTables中使用Bootstrap一次獲取行數。首先,我的代碼從數據庫中提取整個數據並啓動分頁。如何一次獲取一個頁面的數據

但我希望一次加載一個頁面的數據。

我的PHP代碼:

<table id="example1" class="table table-bordered table-striped"> 
    <thead> 
    <tr> 
    <th> Name</th> 
    <th>category</th> 
    <th>Location</th> 

    </tr> 
    </thead> 
    <tbody> 
    <?php foreach ($datastat as $row) { 

    ?> 
    <tr> 
    <td><?php echo $row['fname'];?> <?php echo $row['mname'];?> <?php echo $row['lname'];?></a></td> 
    <td><?php echo $row['category'];?></td> 
    <td><?php echo $row['location'];?></td> 
    </tr> 
    <?php }?> 

    </tbody> 
    <tfoot> 
    <tr> 
    <th> Name</th> 
    <th>category</th> 
    <th>Location</th> 

    </tr> 
    </tfoot> 
    </table>  

我的JavaScript代碼是:

$(function() { 
    $('#example1').dataTable({ 
     "bPaginate": true, 
     "bLengthChange": true, 
     "bFilter": true, 
     "bSort": true, 
     "pageLength": 10 
    }); 
}); 
+0

在文檔站點 – charlietfl

+0

上有服務器端分頁演示和服務器端連接器,這可能是因爲jquery在錯誤的時間被調用(行未準備好)。我會將所有這些數據發送到客戶端,並使用JavaScript或JQuery創建表格行。然後做你的JQuery調用。或者做@charlietfl提到的。 – devtye

+0

@devtye行如何不準備好...表正在生成服務器端。不能發生 – charlietfl

回答

0

您需要實現,以便在從服務器一次檢索一個網頁服務器端處理,請參閱this example

幸運的是,DataTables發行版包含PHP類ssp.class.phpsample code,這使得PHP非常容易使用。

+0

謝謝你的回答Gyrocode但是它的工作只適用於單個表。如何可以爲id做哪一個表的主鍵。 –

相關問題