understanding fnServerData

understanding fnServerData

mgkokomgkoko Posts: 4Questions: 0Answers: 0
edited March 2014 in General
Hi there,

newbie to jquery datatable, but cannot find what I am looking for so far

I got a datatable setup with fnServerData, it works well until I call fnFilter from keyup event one of textboxes on the page.

The ajax request get sent and the data returned from server side is a proper one (it's get filtered records) but the view doesn't get updated for some reason (so when the page first load there are two records, and if I type something into the textbox it returns only record hence datatable should now rerender the view for me and show only one records. Instead it show 'Processing' and that's it thew veiw stay as it is).

coding below, any help appreciated! please let me know if you have any question.

var currentTable = $('#accounts').dataTable({
"bProcessing": true,
"bServerSide": true,
"bSort": false,
"bPaginate": false,
"sDom": '<"top">rt<"bottom"lr><"clear">',
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
$(nRow).addClass('datarow');
},
"sAjaxSource": '/ibweb/1/services/finance/cashbooks.asmx/GetCashbookAccounts',
"fnServerData": function (sSource, aoData, fnCallback, oSettings) {


oSettings.jqXHR = $.ajax({
dataType: 'json',
type: "GET",
url: sSource,
contentType: "application/json; charset=utf-8",
data: aoData,
success: function (msg) {
fnCallback(msg.d);
}
});




},
"fnServerParams": function (aoData) {
aoData.push({ "name": "VesselId", "value": "f2b6bce0-1100-4dc3-8a20-18e0f49bad78" });
aoData.push({ "name": "FromDate", "value": new Date() });
aoData.push({ "name": "ToDate", "value": new Date() });
},
"aoColumns": [
{ "mData": "Name" },
{
"mData": "CreditAccount",
"mRender": function (data, type, full) {
return data ? "Credit" : "Cash";
}
},
{ "mData": "TotalEntries" },
{ "mData": "TotalEntriesWithoutReceipts" },
{ "mData": "TotalSpent" },
{ "mData": "CurrentBalance" }
]
});


$("#txtEntryReference").keyup(function () {
currentTable.fnFilter($(this).val());
});

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    We'd need a link to a test page showing the issue to be able to offer any help I think.

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

    Sure, here you go

    http://yco.devsite.e-flo.info/datatable_test.html

    In the textbox type in 'cap' and you will see the ajax request only return 1 record but datatable just show 'processing'... and won't update the table.

    The 'account' dropdown is another filter that i will add later.
  • mgkokomgkoko Posts: 4Questions: 0Answers: 0
    any updates?
  • mgkokomgkoko Posts: 4Questions: 0Answers: 0
    anyone got same issue. it's because of 'sEcho' I was hard coding the value to be always 1 which is wrong. So on the server side I just read the sEcho value passed from the client side and pass that original value back to the client side (type cast it to INT) and problem solved.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Yup - that is all that is needed (and is what the documentation says :-) ).

    Allan
This discussion has been closed.