How to export csv all row in datatables using ajax source and serverside true ?

How to export csv all row in datatables using ajax source and serverside true ?

luthfiluthfi Posts: 1Questions: 1Answers: 0
edited September 2015 in Free community support

I'm using code igniter for my datatables. if using print on menu tabletoools, datatables can export all row but on csv or excel only page 1. why ? thanks.

This my controler :

    public function tabel_log()
{
    $aColumns = array('tanggal', 'nama', 'ip','type','gadget');
    $sTable = 'log';

    $iDisplayStart = $this->input->get_post('iDisplayStart', true);
    $iDisplayLength = $this->input->get_post('iDisplayLength', true);
    $iSortCol_0 = $this->input->get_post('iSortCol_0', true);
    $iSortingCols = $this->input->get_post('iSortingCols', true);
    $sSearch = $this->input->get_post('sSearch', true);
    $sEcho = $this->input->get_post('sEcho', true);

    // Paging
    if(isset($iDisplayStart) && $iDisplayLength != '-1')
    {
        $this->db->limit($this->db->escape_str($iDisplayLength), $this->db->escape_str($iDisplayStart));
    }

    // Ordering
    if(isset($iSortCol_0))
    {
        for($i=0; $i<intval($iSortingCols); $i++)
        {
            $iSortCol = $this->input->get_post('iSortCol_'.$i, true);
            $bSortable = $this->input->get_post('bSortable_'.intval($iSortCol), true);
            $sSortDir = $this->input->get_post('sSortDir_'.$i, true);

            if($bSortable == 'true')
            {
                $this->db->order_by($aColumns[intval($this->db->escape_str($iSortCol))], $this->db->escape_str($sSortDir));
            }
        }
    }

    if(isset($sSearch) && !empty($sSearch))
    {
        for($i=0; $i<count($aColumns); $i++)
        {
            $bSearchable = $this->input->get_post('bSearchable_'.$i, true);

            // Individual column filtering
            if(isset($bSearchable) && $bSearchable == 'true')
            {
                $this->db->or_like($aColumns[$i], $this->db->escape_like_str($sSearch));
            }
        }
    }

    // Select Data
    $this->db->select('SQL_CALC_FOUND_ROWS '.str_replace(' , ', ' ', implode(', ', $aColumns)), false);
    $rResult = $this->db->get($sTable);

    // Data set length after filtering
    $this->db->select('FOUND_ROWS() AS found_rows');
    $iFilteredTotal = $this->db->get()->row()->found_rows;

    // Total data set length
    $iTotal = $this->db->count_all($sTable);

    // Output
    $output = array(
        'sEcho' => intval($sEcho),
        'iTotalRecords' => $iTotal,
        'iTotalDisplayRecords' => $iFilteredTotal,
        'aaData' => array()
    );

    foreach($rResult->result_array() as $aRow)
    {
        $row = array();

        foreach($aColumns as $col)
        {
            $row[] = $aRow[$col];
        }

        $output['aaData'][] = $row;
    }

    echo json_encode($output);
} 

This my View :

var datatables = $('#table_log').dataTable(
{
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"bDeferRender": true,
"sServerMethod": "GET",
"sPaginationType": "full_numbers",
"order": [[ 0, "desc" ]],
"iDisplayLength" : 8,
"sAjaxSource": "<?php echo base_url(); ?>index.php/con_datatables/tabel_log",
"aoColumns":
[
{ "title": "Tanggal","sWidth": "25%","aadata": "tanggal" },
{ "title": "Nama","sWidth": "15%","type": "natural","aadata": "nama" },
{ "title": "IP","sWidth": "20%","aadata": "ip" },
{ "title": "Type","sWidth": "20%","aadata": "type" },
{ "title": "Use","sWidth": "20%","aadata": "gadget" }
],
"sDom": '<"H"Tlfr>t<"F"ip>',
"oTableTools":
{
"sRowSelect": "os",
"sSwfPath": "<?php echo base_url(); ?>/js/copy_csv_xls_pdf.swf",
"aButtons":
[
{
"sExtends": "copy",
"oSelectorOpts": { filter: 'applied', order: 'current' }
},
{
"sExtends": "csv",
"oSelectorOpts": { filter: 'applied', order: 'current' },
"sFileName": ".csv"
},
{
"sExtends": "xls",
"oSelectorOpts": { filter: 'applied', order: 'current' },
"sFileName": "
.xls"
},
{
"sExtends": "pdf",
"oSelectorOpts": { filter: 'applied', order: 'current' },
"sFileName": "*.pdf"
},
{
"sExtends": "print",
"oSelectorOpts": { filter: 'applied', order: 'current' }
}
]
}
} );

This discussion has been closed.