Updating data from webservice
Updating data from webservice
Mungoid
Posts: 2Questions: 0Answers: 0
As much as i hate to post seemingly easy questions, I am lost as to how to update my data and have tried everything i can think of.
I use a datatable to show search results in a page. There are a number of fields, dropdowns, etc the user can fill out, hit search and update the table using a post to a webservice. The initial call works great and my results show just fine. I also use fnRowCallback to modify some cells to links and dropdowns. All initially work just fine.
However, when i add some search criteria and hit search button, i call fnDraw() but my web service does not get the updated json object. It seems to be using an empty one. Below is the code i use. If anyone could inform me as to what im missing, i would be highly grateful!
I cant link to a working page, but here is the code i call when i hit my search button. I was trying fnReloadAjax but then found that its useless with my situation so I switched to fnDraw() instead but i am not sure how to pass my updated json object to the webservice.
[code]
$("#btnSearch").button().click(function (e) {
e.preventDefault();
// This code updates the json object that needs to pass to webservice. Not sure how to pass this to server now tho
var datap = new Object;
datap.searchCriteria = $(".curriculumSearchCriteria").serializeObject();
//oTable.fnReloadAjax();
oTable.fnDraw();
});
[/code]
And Here is my initial code that seems to work
[code]
var datap = new Object;
datap.searchCriteria = $(".curriculumSearchCriteria").serializeObject();
oTable = $("#example").dataTable({
"bPaginate": false,
"bFilter": false,
"bInfo": false,
"bJQueryUI": false,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "CurriculumServ.asmx/SearchCurriculum",
"sAjaxDataProp": "d",
"aoColumns": [
{ "mDataProp": "CurriculumTitle" },
{ "mDataProp": "CurriculumAuthor" },
{ "mDataProp": "DocList" },
{ "mDataProp": "Sessions" },
{ "mDataProp": "FirstEventDate" }
],
"fnServerData": function (sSource, aoData, fnCallback, oSettings) {
oSettings.jqXHR = $.ajax({
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
processData: false,
url: sSource,
data: JSON.stringify(datap),
success: fnCallback
});
},
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
// removed to save space
}
});
[/code]
I use a datatable to show search results in a page. There are a number of fields, dropdowns, etc the user can fill out, hit search and update the table using a post to a webservice. The initial call works great and my results show just fine. I also use fnRowCallback to modify some cells to links and dropdowns. All initially work just fine.
However, when i add some search criteria and hit search button, i call fnDraw() but my web service does not get the updated json object. It seems to be using an empty one. Below is the code i use. If anyone could inform me as to what im missing, i would be highly grateful!
I cant link to a working page, but here is the code i call when i hit my search button. I was trying fnReloadAjax but then found that its useless with my situation so I switched to fnDraw() instead but i am not sure how to pass my updated json object to the webservice.
[code]
$("#btnSearch").button().click(function (e) {
e.preventDefault();
// This code updates the json object that needs to pass to webservice. Not sure how to pass this to server now tho
var datap = new Object;
datap.searchCriteria = $(".curriculumSearchCriteria").serializeObject();
//oTable.fnReloadAjax();
oTable.fnDraw();
});
[/code]
And Here is my initial code that seems to work
[code]
var datap = new Object;
datap.searchCriteria = $(".curriculumSearchCriteria").serializeObject();
oTable = $("#example").dataTable({
"bPaginate": false,
"bFilter": false,
"bInfo": false,
"bJQueryUI": false,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "CurriculumServ.asmx/SearchCurriculum",
"sAjaxDataProp": "d",
"aoColumns": [
{ "mDataProp": "CurriculumTitle" },
{ "mDataProp": "CurriculumAuthor" },
{ "mDataProp": "DocList" },
{ "mDataProp": "Sessions" },
{ "mDataProp": "FirstEventDate" }
],
"fnServerData": function (sSource, aoData, fnCallback, oSettings) {
oSettings.jqXHR = $.ajax({
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
processData: false,
url: sSource,
data: JSON.stringify(datap),
success: fnCallback
});
},
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
// removed to save space
}
});
[/code]
This discussion has been closed.
Replies
When using server-side processing, DataTables requires that certain parameters be sent to the server, and certain parameters to come back (documented here: http://datatables.net/usage/server-side ). My guess is that the content in `datap` does not have those parameters - would I be correct in that assumption? Do you really need server-side processing ( bServerSide )? Are you working with tens of thousands of records?
Allan
Thanks for your help! And my ineptitude with datatables aside, you did a fantastic job with this tool =-)
---
For now there probably wont be that many rows but over time there might be. As far as the specific params set in datap, you are totally correct. I overlooked those and didnt send them. So on that note I decided to just disable bServerSide as there will only be a couple hundred records at first.
However, after i turned that off my webservice doesnt get called at all on fnDraw now. This is why i thought i needed bServerSide initially. What am i missing? EDIT: I passed true to fnDraw and it now hits the server but I'm still not sure how to pass my updated JSON object to the server.