understanding fnServerData
understanding fnServerData
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());
});
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());
});
This discussion has been closed.
Replies
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.
Allan