fnServerData fine with JQ 1.3.2, not working with 1.4.2 and above

fnServerData fine with JQ 1.3.2, not working with 1.4.2 and above

pierrempierrem Posts: 4Questions: 0Answers: 0
edited December 2011 in Bug reports
The following datatable was perfectly loaded when I was using JQ 1.3.2. Since I moved to the new JQ 1.6.2 (and that stands also with JQ 1.4.2), the datatable is not loaded, no row is displayed. And the alert on fnDrawCallback does not pop up (which makes sense). Did I misused somthing?
Any hints?
PS: the problem is the same with both versions of datatables, 1.7 and 1.8
Here the dynamiccally loaded script:
[code]

$(document).ready(function() {
var DIR_INCLUDE = "../common/"
$('#datatable').dataTable( {
"iDisplayLength": 2000,
//"aLengthMenu": [[25, 100, 500, -1], [25, 100, 500, "Toutes"]],
//"aLengthMenu": [[25, 100, 500], [25, 100, 500]],
"aLengthMenu": [[-1, 10, 50, 500], ["Toutes", 10, 50, 500]],
"bProcessing": true,
"bServerSide": true,
//"sPaginationType": "full_numbers",
"oLanguage": { "sUrl": DIR_INCLUDE + "French.txt"},
"sAjaxSource": "<?php echo 'competence_selection_json_creation.php?&eval='.$evaluation_id.'';?>",
"fnDrawCallback": function( oSettings ) {
alert( "DataTables has redrawn the table" );
},
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( { "name": "name", "value": "value" } );
$.getJSON( sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json)
} );
}
} );
} );

[/code]
Thanks for your help

Replies

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Looks fine to me. Are yo getting any errors on the Javascript console, and can you give us a link to the page?

    Allan
  • pierrempierrem Posts: 4Questions: 0Answers: 0
    Hi Allan,

    Thanks for answering so quickly.
    No, actually, I got no errors on the console. The result I get from the ajaxsource looks correct, and is the same in both cases (see below a part of it). It seems to me that the draw event is not fired with newer JQ, which I agree seems unbelievable (fnDrawCallback does not dispaly the alert with jq 1.4). To be frank, I suspect more a configuration problem on my side than a real bug in either jquery or datatables...
    I can prepare a page for you, but I will need some time because the page that causes the problem is inside my product. Ineed to prepare a direct link for you, otherwise you will loose too much time browing our numerous files and directories (and the product is in French :-)
    Meanwhile, if yo have any suggestions, I'll appreciate.
    Thanks again.

    [code]

    {"sEcho": 1, "iTotalRecords": 371, "iTotalDisplayRecords": 10, "aaData": [ ["HS ",
    "","","4","","","","","","O","","Savoir-faire","Réaliser","reconnaissance lentille convergente divergente","toucher ou visualisation d\'un texte","",
    ""],
    ["HS ","","","4","","","","","","O","","Savoir

    ......... a bunch of data ........ ending with:

    ,"Savoir-faire","Réaliser","Réaliser un prélèvement d\'un liquide","Prélever un liquide avec un agitateur","Nettoyage de l\'agitateur",
    ""]] }
    [/code]
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Okay a couple of things to check:

    1. All libraries are fully up-to-date. jQuery, DataTables and if you use the jQuery validate plug-in - definitely update that.

    2. iTotalDisplayRecords - you've got that as 10. It _must_ be the same as iTotalRecords _unless_ there is a filter applied to the table: http://datatables.net/usage/server-side

    3. sEcho - that must be the same value as what DataTables sends to the server. It should never be 0, and only 1 on the first draw (its a counter).

    Those are the "obvious" things off the top of my head.

    Allan
  • pierrempierrem Posts: 4Questions: 0Answers: 0
    Allan,

    I have investigated your points:

    1.Actually, I have this problem since I upgraded jQuery a few days ago (for correcting another issue with IE). I am using:
    jq: 1.3.2 or 1.4.2 or 1.6.2
    jq-ui: 1.8.2 or 1.8.16
    and datatables: 1.7.0 or 1.8.2
    - With jQuery 1.4.2 or 1.6.2, all the combinations fail and show the problem,
    - if I use the jQuery 1.3.2, all combinations work fine
    I am not using jQuery validate

    2. I have changed the iTotalDisplayRecords to make it equal to iTotalRecords. This does not change anything.

    3. sEcho: I already found that strange. Indeed, it is always 1: the server always receives 1 and sends back 1. Btw, I never set this value. Should I? Does this prevents the data to be displayed? (I interpretate the sEcho as a token exchanged between client and server, so if it remains to 1, there might be a problem). The fact it never increases, is possibly due to the way the program is built:
    a. when the user pushes a given button, a PHP script ("remplit_modal.php") generates and echoes a page that contains the script I mentionned above;
    b. that page is dynamiccally loaded in a modal box (jQuery plug-in "simplemodal") that is opened (and therefore executes the script at doc ready time, ask the data to teh server and display the datatable).
    [code]

    $('#boite_modal').load("remplit_modal.php?box_id=" + id, function() {
    $('#boite_content').modal({
    overlayClose:true,
    opacity:60,
    overlayCss: {backgroundColor:"#555555"}
    //autoResize:true
    });
    });
    [/code]

    There are likely other ways of achieving the same behavior, and I will manage if we don't find the solution (but it is a bunch of rework...).
    What actually bothers me is the fact it is working with old jQuery version and not with the more recent...
This discussion has been closed.