2013-12-16 188 views
0

我正在使用codeigniter的網站上工作,並且我有這張表格將充滿來自數據庫的信息。 當我填充我的表格時,需要相當長的一段時間,因爲我的數據庫中有15000行,並且瀏覽器在加載一兩分鐘後卡住了。使用許多元素填充表格

這裏是我的代碼部分

查看:

<div class="portlet-body"> 
       <table class="table table-striped table-bordered table-hover table-full-width" id="sample_1"> 
        <thead> 
         <tr> 
          <th>ID</th> 
          <th class="hidden-xs">Serial Number</th> 
          <th class="hidden-xs">Codigo</th> 
          <th class="hidden-xs">Estado</th> 
          <th class="hidden-xs">Data de inserção</th> 
          <th class="hidden-xs">Provider</th> 
         </tr> 
        </thead> 
        <tbody> 
         <?php foreach ($query->result_array() as $row): {        

         ?> 
         <tr> 
          <td><?php echo $row['product_id'] ?></td> 
          <td><?php echo $row['serial_number'] ?></td> 
          <td class="hidden-xs"><?php echo $row['product_code'] ?></td> 
          <td class="hidden-xs"><?php echo $row['product_status'] ?></td> 
          <td class="hidden-xs"><?php echo $row['product_insertion_date'] ?></td> 
          <td class="hidden-xs"><?php echo $row['product_provider'] ?></td> 
         </tr> 

         <?php } endforeach; ?> 

        </tbody> 
       </table> 
       </div> 

控制器:

public function loadProdutos(){ 

    $this->load->model('produtos_model'); 
    $tmp = $this->produtos_model->getProdutos(); 

    $data['query'] = $tmp; 


    $this->load->view('produtos',$data); 
} 

型號:

function getProdutos() { 

    $query = $this->db->get('products'); 
    return $query; 
} 

我的問題是,如果有一個最佳實踐在這種類型中情況,還是其他方式做到這一點?

回答

2

第一選項

你可能會想嘗試,把一個分頁在那裏,這樣的成績被劃分成不同的網頁,並一次不加載。

笨提供了自己的音樂庫一pagination

第二個選項

您也可以嘗試把一個ajax負載在那裏,當你到達頁面的底部,雖然這可能是一個有點難做。

你可以找到一個教程here,或搜索谷歌找到一個適合你。

第三選項

負載更多的按鈕,類似於上面的那個,但沒有「如果您在網頁底部的」

如果您需要在執行這些任何幫助,讓我知道,我會盡可能幫助。 如果這三種選擇都不是你想要的,那麼我的想法也沒有了。

0

您最簡單最快捷的解決方案可能是使用pagination。這將減少服務器負載以及瀏覽器的負載,因爲它只需一次顯示幾行,而不是全部15,000行。

0

你需要的是分頁,可以非常方便的與DATA_SOURCE AJAX的DataTable實現這一點:http://datatables.net/examples/data_sources/ajax.html

什麼你也可以做的是gzip壓縮的內容。當你輸出15.000行時,你可能會有一個大小爲幾兆的請求。當你使用gzip時,它會變得更小。

但仍然是最好的更新是分頁。

0

你可以使用分頁選項。如果db有更多的行,則加載數據是更好的選擇。因爲它只加載每個頁面。