Data Table crashes for records above 40

Data Table crashes for records above 40

jawadxivjawadxiv Posts: 3Questions: 1Answers: 0
edited November 2014 in Free community support

I am using data table to display data returned by a SQL Server 2008 procedure called in Codeigniter via Ajax($POST). Initially I made a very simple procedure with no input parameters, it only returns a list of JSON objects. Below are my questions and my Codeigniter function returning JSON, AJAX function and JSON structure returned by my Codeigniter function .:

1) When my JSON data size goes above 45+ , it crashes and gives me below error. It works fine for data below 40(Which does not make sense as i have to display much larger around 1000+ records)(one more thing i noticed in my fire bug when i return more then 40 records i dont see a json tab in my fire bug console it only says html where i returned json encoded data):

DataTables warning: table id=example - Requested unknown parameter 'AppointmentID' for row 0. For more information about this error, please see http://datatables.net/tn/4

2) What if one of my procedure returns lets say 5000+ record and i want to display it in data table, is my way of doing it right? Or i should use some other best practices:

public function executeProc()
 {
    $sqlsrvr = $this->load->database('test', true);

    // Get the input values of the procedure

    $arr = array();
    parse_str($_POST['str'],$arr); 

    //get Procedure Name
    $procName = $_POST['procName'];

    $sp ='exec secondProc';
    $query = $sqlsrvr->query($sp);//->result();
    $jawad =  $query->result_array();

    $this->output->set_header('Content-type: application/json');  
     echo json_encode($jawad);

 }

AJAX function

$(document).on('click','#executeProc',function(e){

$('#demo').html('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>');
  e.preventDefault();

  var jawad = $( ".jawad" ).serialize();

 $.post('<?=base_url();?>command/executeProc',
    {str:jawad,procName:$('#procName').val()},

   function(html){
    //loading data table on return
    $('#example').dataTable( {
     "data": html,
    "columns": [
        { "data": "AppointmentID" },
        { "data": "FirstName" },
        { "data": "LastName" },
        { "data": "AppointmentDate" }
    ]
  } );

    });

});

JSON STRUCTURE:

[
    {
        "AppointmentID": "1",
        "FirstName": "Test",
        "LastName": "test",
        "AppointmentDate": "2013-01-12"
    },
    {
        "AppointmentID": "2",
        "FirstName": "dfg",
        "LastName": "dfg",
        "AppointmentDate": "2013-01-01"
    }
]

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Can you please link to a test page showing the crash so we can debug it.

    Allan

  • jawadxivjawadxiv Posts: 3Questions: 1Answers: 0

    @allan: After a lot of fighting around I was able to know that if my JSON chunk increases than 4 KB, it is not displayed.

    For records lesser then 4KB they are displayed, but i am totally stuck because my what if my procedure returns 1000 rows how can i show them in data table.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    4KB sounds a lot like the cookie limit. Are you using cookies at all?

    There is nothing in DataTables that will restrict the size of the JSON that is loaded. I've seen tables which load 50+MB of data.

    Allan

  • jawadxivjawadxiv Posts: 3Questions: 1Answers: 0

    no man not using cookies at all.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Okay - sorry I'm not able to help without a link to the page showing the issue.

    Allan

This discussion has been closed.