Simple Implementation with server side processing not working
Simple Implementation with server side processing not working
Hi,
In my HTML I added only 2 lines:
I want the jQuery/Datatable to call a WebService to pull column names and data (with paging but no search or sorting to keep it simple). I have tried many ways but I have not been able to get it to work. Can you please help?
Here is the jQuery calls:
var oTable;
oTable = $('#dte_2').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost/api.asmx/List?what=<%= Request("what") %>",
"pagingType": "full_numbers",
"bFilter": false,
"bLengthChange": false,
"ordering": false,
"aoColumns": [
{ "sClass": "center", "bSortable": false },
null,
null,
null,
{ "sClass": "center" },
{ "sClass": "center" }
]
});
Note: If I remove adColumns, the data table no longer displays.
Here is the json I am sending from the webservice:
{
"draw": 1,
"recordsTotal": 57,
"recordsFiltered": 57,
"columns": [
{ "title": "NAME" },
{ "title": "Col2" },
{ "title": "Col3" },
{ "title": "Col4" },
{ "title": "Col5" },
{ "title": "Col6" }
],
"data": [
[ "Cedric", "Kelly", "Senior Javascript Developer", "Edinburgh", "29th Mar 12", "$433,060" ]
]
}
Replies
looks like my code did not highlight:
My HTML Code
Also, the issues has gotten eaten up:
1. The table captions are not displayed.
2. On pagination, the webservice is called and it sends updated data but the table display does not change from where it was.
Any help is greatly appreciated!
Because you are using the legacy sAjaxSource property DataTables will be sending the legacy parameters and expecting legacy parameters in return. But instead you are returning the parameters expected in 1.10.
In the first instance I'd suggest you use
ajax
instead of sAjaxSource. If that doesn't help read over the server-side processing manual page. And if that doesn't help, post a link to the page so we can take a look.Allan
Thanks Allan for your response. If I use Ajax instead of sAjaxSource then I get Javascript error when I do not have any columns defined in table.
Here is the basic test html page and JSON file. Once I get it to work I will further extend it by adding code behind.
http://www.cobramart.com/DataTable.html
JSON File:
http://www.cobramart.com/data.json
There are 2 tables. You can see that the 2nd one does not have column information and I get JS error.
You have to define the columns client-side. No DataTables version (yet) has supported getting the columns from its own Ajax request.
Allan