bServerSide, bProcessing issues

bServerSide, bProcessing issues

codemonkcodemonk Posts: 24Questions: 0Answers: 0
edited April 2012 in DataTables 1.9
Hello all,

i am having issues with datatables. I am recently learning it and its a wonderful addon! i was working with local data and everything was working great. I am now switching over to dynamic and loading from my server, and im having issues. I cannot load any date from any server, my server or the example server. However i can load from a file locally. Right now it just has the table headers and footers and the processing... text stuck.

Table Initialization
[code]

$(document).ready(function(){

var oTable = $('#example').dataTable({
"bJQueryUI": true,
"bStateSave": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": $.get("http://localhost:8888/ajax"),
//"sAjaxSource": "data.ajax",
//"sAjaxSource": "http://datatables.net/examples/examples_support/json_source.txt",
"sPaginationType": "full_numbers",
"sDom": 'R<"H"lfr>t<"F"ip<',
"bAutoWidth": false,

//"sDom": 'R<"H"lfr>t<"F"ip<',

});
//more code here

[/code]

HTML code
[code]




Rendering engine
Browser
Platform(s)
Engine version
CSS grade







Rendering engine
Browser
Platform(s)
Engine version
CSS grade




[/code]


Ive tried many things to solve my issue. i even used the php server file from the serverside example page. I created a the following test page:
[code]





$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://www.datatables.net/examples/examples_support/server_processing.php"
} );
} );






Rendering engine
Browser
Platform(s)
Engine version
CSS grade




Loading data from server




Rendering engine
Browser
Platform(s)
Engine version
CSS grade






[/code]

for a while i was getting nCell is undefined.

here is my debuged table: http://debug.datatables.net/owugok

at this point im out of ideas and not knowing what to do to get things working. So a few questions? How should i initialize the HTML table not datatable but HTML table. should it have a specific class?

My thought is that im not creating the HTML table correctly and i dug into the source of the example and i noticed that under tbody there was

[code]

Loading data from server

[/code]
and when i insert that i get following error

DataTables warning (table id = 'example'): Requested unknown parameter '1' from the data source for row 0

any ideas? Any help would be greatly appreciated.

Replies

  • drchanixdrchanix Posts: 20Questions: 0Answers: 0
    I have this kind of problem too and Allan helped me solved it.
    I am using .Net MVC, but you might want to take a look.
    http://datatables.net/forums/discussion/9610/how-to-display-returned-records-from-jsonresult-in-mvc.net#Item_11
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    > DataTables warning (table id = 'example'): Requested unknown parameter '1' from the data source for row 0

    Your debug trace shows that there is noting being returned by the server, so this error is stop on :-). It suggests that the problem is in the server-side processing script and it not returning any data (see the Firebug / Inspector console to see that).

    Allan
  • codemonkcodemonk Posts: 24Questions: 0Answers: 0
    edited May 2012
    im still having issues. I can view the JSON in fiddler. I am using [code]"sAjaxSource": $.get("http://datatables.net/examples/examples_support/server_processing.php"),[/code] with a good return according to fiddler. however it doesn't display. I read the posting suggested, but i dont think it applies in this case as the data i am receiving is not the same. if you visit the URL above, you'll notice how the DATA is formed, it is not the same as the blog. i am still not getting the data sent to my table. is there any quick way to have a good test data? so i can test it out furthermore?

    http://debug.datatables.net/ofamuh
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    Hi,

    That code would assign a jQuery XHR object to the sAjaxSource parameter, while DataTables is expecting a simple string there. Try something more like this:

    [code]
    "sAjaxSource": "/examples/examples_support/server_processing.php",
    [/code]

    (note that the http://datatables.net reference wouldn't work because of cross site scripting - the browser would block that - you need to use a relative path or JSONP).

    What does the data that you are getting back from your own JSON source look like?

    Allan
  • codemonkcodemonk Posts: 24Questions: 0Answers: 0
    Hey allan,

    I really appreciate the help. I am new, and i haven't quiet gotten my own json source, I just got the table up and running off a txt file locally, which looks like:

    [code]{ "aaData": [
    ["Trident","Internet Explorer 4.0","Win 95+","4","X"][/code]

    i have my web service written in nodejs to return that exact same string, and that when i got the " DataTables warning (table id = 'example'): ..." but it was just a string.

    Thank you for your patients, i am new to jquery and datatables. the reason i ask for sample data is because i received a new machine, and i need to install all the applications all over again, but i need to put in a help desk ticket so that will take some time :P

    i guess i'll have to go ahead and create a json in my webservice and see if i can get something working. but i'll have to wait until i get my machine with the software i need. Thanks again.

    i will report my findings. Thank you so much for your help.
  • codemonkcodemonk Posts: 24Questions: 0Answers: 0
    edited May 2012
    quick update, i finally got some data:

    http://debug.datatables.net/oratop

    "DataTables warning (table id = 'example'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error."

    at this point my guess is im not building my JSON correctly, given that i just googled php simple json. :P but using the method above,
    setting [code]"sAjaxDataProp": "",[/code]

    and [code]
    "aoColumns": [
    { "mDataProp": "cell1" },
    { "mDataProp": "cell2" },
    { "mDataProp": "cell3" }
    ][/code]

    and here is my simple php

    [code]<?php
    $output = array('cell1' => 1, 'cell2' => 2, 'cell3' => 3);

    echo json_encode($output);
    ?>
    [/code]

    UPDATE: I dont think that error code is correct, im working with files locally and on a dev machine. and the dev machine didnt throw out any error, but has php installed. Locally i have no php. and cannot seem to generate the debug on the local machine.
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    If you are using a simple text file - then you most certainly don't want "bServerSide": true. That enables server-side processing: http://datatables.net/usage/server-side .

    With your latest PHP - try this:

    [code]
    <?php
    $output = array('cell1' => 1, 'cell2' => 2, 'cell3' => 3);

    echo json_encode( array( $output ) );
    ?>
    [/code]

    remember that DataTables is expected an array of rows of data (which themselves can be arrays or objects). Have a look at my Ajax examples: http://datatables.net/examples/ - if you scroll down the page a bit, they actually show you the JSON returned from the server for each.

    Allan
  • codemonkcodemonk Posts: 24Questions: 0Answers: 0
    thank you very much allan, I got it working as mentioned above, but more important i got it working in the usual sense. I will include my code for those who have similar issues.

    php code
    [code]<?php

    $iTotal = 5;
    $iFilteredTotal = 5;

    $output = array(
    "sEcho" => 0,
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => $iFilteredTotal,
    "aaData" => array()
    );

    for($i =0; $i<101; $i++)
    {
    $row = array($i,$i+1,$i+2);
    $output['aaData'][] = $row;
    }

    echo json_encode( $output );

    ?>[/code]

    otable initialization
    [code]var oTable = $('#example').dataTable({
    "bJQueryUI": true,
    "bStateSave": true,
    "bProcessing": true,
    "sAjaxSource": "php.php",
    "sPaginationType": "full_numbers",
    "sDom": 'R<"H"lfr>t<"F"ip<',
    "bAutoWidth": false,[/code]
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    Good to hear you got it working.

    For sake of completeness, it is worth noting that sEcho, iTotalRecords and iTotalDisplayRecords are only needed when you are using server-side processing ( http://datatables.net/usage/server-side ). They are harmless as they are atm, since DataTables will just ignore them without server-side processing, but just incase it confuses someone!

    Allan
This discussion has been closed.