0

i am new to SOAP and Codeigniter. My problem is i can get the valid json but the data is not display in datatable. i am using codeigniter as framework and SOAP as web service. Here's my code so far:

server:

function get_history(){

      $CI =& get_instance();
    $CI->load->database();

     $aColumns = array('time', 'ip_address', 'player_item','comp_item','result');
    // DB table to use
    $sTable = 'rps';
    //

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

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

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

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

    /* 
     * Filtering
     * NOTE this does not match the built-in DataTables filtering which does it
     * word by word on any field. It's possible to do here, but concerned about efficiency
     * on very large tables, and MySQL's regex functionality is very limited
     */
    if(isset($sSearch) && !empty($sSearch))
    {
        for($i=0; $i<count($aColumns); $i++)
        {
            $bSearchable = $CI->input->get_post('bSearchable_'.$i, true);

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

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

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

    // Total data set length
    $iTotal = $CI->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;
    }

  return json_encode($output);

client:

 $(document).ready(function() {

    var oTable = $('#jsontable').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": 'http://192.168.19.25/xampp/CodeIgniter/index.php/Soapclient123/history',
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "iDisplayStart ":20,
        "aaSorting": [[ 0, "desc" ]],
        "oLanguage": {
            "sProcessing": "<img src='http://192.168.19.25/assets/images/ajax-loader_dark.gif'>"
        }, 

         "fnInitComplete": function() {
                //oTable.fnAdjustColumnSizing();
         },
                'fnServerData': function(sSource, aoData, fnCallback)
            {
              $.ajax
              ({
                'dataType': 'json',
                'type'    : 'POST',
                'url'     : sSource,
                'data'    : aoData,
                'success' : fnCallback
              });


            }

    } );



} );
khalid as
  • 69
  • 8
  • That is because you are using datatables server side, which uses a different format when displaying the data, please visit: http://stackoverflow.com/questions/29197058/datatables-server-side-processing-in-typo3-with-fce-and-templavoila/29197393#29197393 or http://legacy.datatables.net/usage/server-side for more info – Arzgethalm Mar 30 '15 at 05:03
  • i have edited the code to server side..but data also not display in datatable. – khalid as Mar 30 '15 at 09:40

0 Answers0