The jquery datatables are not loading the data

The jquery datatables are not loading the data

dcn.1990dcn.1990 Posts: 4Questions: 2Answers: 0
edited May 2016 in Free community support

Hi everyone, first of all this plugin is great. But I am having this one issue, I am trying to fetch reports but the values do not load in the datatable. I have done a print_r on the function I am trying to load in the datatable. Kindly note I am using Codeigniter. I will post the function I am printing. If anything else is required that I may help kindly let me know.

On print_r($this->report_m->getReport()); I get the following:

{"sEcho":0,"iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":[["2016-05-08",my.n","0001","sun1234","My Product Name","SUN4321","16.95","5.95","CHEQUE","Telephone"]],"sColumns":""}

On other datatables I had done. The sColumns gives the column names but here it is blank. Can anybody help me as to how to get this to work?

I will include the datatables code to to verify where I have gone wrong.

<script type="text/javascript"> $(document).ready(function() { var oTable = $('#big_table').dataTable( { "aoColumnDefs": [ { "sWidth": "10.5%", "aTargets": [ 9 ] } ], "bProcessing": false, "aaSorting": [[0,'desc']], "bServerSide": true, "sAjaxSource": '<?php echo base_url(); ?>index.php/agent/report/list_report', "bJQueryUI": true, "sPaginationType": "full_numbers", "iDisplayStart ":25, "oLanguage": { "sProcessing": "<img src='<?php echo base_url(); ?>img/ajax-loader.gif'>" }, "fnInitComplete": function() { //oTable.fnAdjustColumnSizing(); }, "fnRowCallback": function( nRow, aData, iDisplayIndex ) { nRow.className = aData[9]; }, 'fnServerData': function(sSource, aoData, fnCallback) { debugger; $.ajax ({ 'dataType': 'json', 'type' : 'POST', 'url' : sSource, 'data' : aoData, 'success' : fnCallback }); } } ) } ); </script>

Answers

  • allanallan Posts: 64,090Questions: 1Answers: 10,569 Site admin

    "sEcho":0,

    sEcho should never be zero. That suggests that server-side processing hasn't been fully implemented in your server-side script (note you are referring to the legacy documentation for parameters such as sEcho.

    Allan

  • dcn.1990dcn.1990 Posts: 4Questions: 2Answers: 0
    edited May 2016

    Any Idea how to get "sEcho":1, ? Because In another table, in fact for which I followed the exact same code, On printing the response I get the same - "sEcho":0, and it works perfectly.

  • allanallan Posts: 64,090Questions: 1Answers: 10,569 Site admin

    sEcho is a parameter sent to the server by DataTables when it requests the data. As the legacy manual says:

    An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.

    Which means that your <?php echo base_url(); ?>index.php/agent/report/list_report script is not correctly seeing the request from the client-side and returning the required data.

    Allan

  • dcn.1990dcn.1990 Posts: 4Questions: 2Answers: 0

    Hello Sir,

    The data is now loading, although this is the same sEcho:0 and sColumns:":" The data not loading was my fault. I was calling the wrong function in the <?php echo base_url(); ?>index.php/agent/report/list_report

    I thank you for your interest. I guess I need some more knowledge to fully understand the working of this wonder you have created.

This discussion has been closed.