数据表中所有页面总量不工作,只工作当前页面

datatable total amount of all pages dont work, just work the current page

本文关键字:工作 当前页 数据表      更新时间:2023-09-26
请帮我解决这个问题。我想从我的数据表中获得所有页面的总量,但它根本不起作用。

文件说,api。列(3).data();//我可以像这样获取所有数据api。Column (3, {page: "current"}).data();//我可以得到当前页面

但我是这样放的(api)。列(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);
    }
   });

谢谢提前! !

您正在使用"serverSide": true的服务器端处理模式,其中仅为当前页面发送数据。这就是为什么所有页面的数据对jQuery数据表是不可用的,只有当前页面的数据。

你可以改变你的服务器端脚本在服务器端执行计算,并发送所需的数据作为一个额外的数据参数,你可以在回调后通过ajax.json() API方法访问。