fnServerParams problem/question

fnServerParams problem/question

MPeter1975MPeter1975 Posts: 31Questions: 0Answers: 0
edited February 2012 in General
Hi,

Problem:

[code]
var oTable
var iPeriodStart; //
var iPeriodEnd; //

// Full Ajax Server-Side Processing
$(document).ready(function() {
oTable = $('#mytable').dataTable( {
// Ajax / Server Side
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/server_processing.php",
"fnServerParams" : function (aoData) {
aoData.push({
"name": "iPeriodStart",
"value": iPeriodStart
})
aoData.push({
"name": "iPeriodEnd",
"value": iPeriodEnd
})
},
[...]
});

$('#selectPeriods').submit( function() {
oTable.fnDraw(false);
iPeriodStart = 300;
return false;
});
});
[/code]

When the page first loads the iPeriodStart and iPeriodEnd variables are undefined in GET params. When I hit my own submit button the situation is the same, both parameters are undefined. When I hit my submit button again suddenly iPeriodStart becomes 300. Why only the third GET request contains the good value when the second one should have to?

Question: I have my own selectPeriods form with two select lists and one submit button. How can I pass the selected values to the iPeriodStart custom parameter?

Thanks!

Replies

  • MPeter1975MPeter1975 Posts: 31Questions: 0Answers: 0
    Sorry. I was very tired. Of course I need to call the fnDraw after I set the variables. Correct code:
    [code]
    $('#selectPeriods').submit( function() {
    var sel1 = document.getElementById('periodStart');
    var sel2 = document.getElementById('periodEnd');
    iPeriodStart = sel1.options[sel1.selectedIndex].value;
    iPeriodEnd = sel2.options[sel2.selectedIndex].value;
    oTable.fnDraw(false);
    return false;
    });
    [/code]
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Nice one - thanks for updating us on how you got on :-)

    Allan
This discussion has been closed.