2016-11-15 28 views
0

請幫我解決這個問題。我想從我的數據表中獲得所有頁面的總量,但它根本不工作。 (文件說, api.column(3).data(); //我可以得到像這樣的所有數據 api.column(3,{page:「current」}).data(); //我只能得到當前頁面datatable所有頁面的總數量不工作,只是工作當前頁

但是我採用這種方式(api.column(3).data())並且不工作從所有頁面獲取所有數據,這是因爲我將api .column(3,{page:「current」}).data();只要;

下面的代碼:

$(document).ready(function() { 

//datatables 
table = $('#table').DataTable({ 

    "processing": true, //Feature control the processing indicator. 
    "serverSide": true, //Feature control DataTables' server-side processing mode. 
    "order": [], //Initial no order. 

    // Load data for the table's content from an Ajax source 
    "ajax": { 
     "url": "<?php echo site_url('Locacao/ajax_list')?>", 
     "type": "POST" 
    }, 
    "pageLength": 10, 

    //Set column definition initialisation properties. 
    "columnDefs": [ 
    { 
     "targets": [ -1 ], //last column 
     "orderable": false, //set not orderable 

    }, 
    ],    

    "footerCallback": function (row, data, start, end, display) { 
     var api = this.api(), data; 

     // Remove the formatting to get integer data for summation 
     var intVal = function (i) { 
      return typeof i === 'string' ? 
       i.replace(/[\$,]/g, '')*1 : 
       typeof i === 'number' ? 
        i : 0; 
     };   


     // Update footer    

     // Total over all pages 
     valor = api 
      .column(3) //here should work but nothing 
      .data() 
      .reduce(function (a, b) { 
       return intVal(a) + intVal(b); 
      }, 0); 

     // Update footer 
     $(api.column(3).footer()).html(valor); 
    } 

    }); 

感謝提前!

+0

你忘了使用語言標籤.... –

+0

對不起,我把:' 「oLanguage」:{ 「sLengthMenu」: 「LocaçõesPOR頁面:_MENU_」, 「sInfo」: 「_TOTAL_Locações」 「sInfoFiltered」:「(Total:_MAX_Locações)」 },'但是還沒有工作 – Luciano

回答

1

您正在使用服務器端處理模式"serverSide": true,其中數據僅針對當前頁面發送。這就是爲什麼所有頁面的數據對jQuery DataTables不可用,只有當前頁面數據。

您可以更改您的服務器端腳本以在服務器端執行計算並將所需數據作爲附加數據參數發送,您可以稍後通過ajax.json() API方法在回調中訪問。

+0

是的,我認爲是的,因爲我在數據表中使用另一個Ajax請求來獲得數據庫中的'總量' 。所以工作得很好。以我的方式解決,但這種我想要的方式仍然沒有找到解決的辦法。謝謝! – Luciano