Datatables AJAX
Datatables AJAX
Hey there,
I know there are probably a lot threads about this topic, but I need some clarification.
AJAX initially has nothing to do with server side processing of the data right?
So what I want to do is, get the data from my server pass it into the datatable and use all the functionality (sorting, searching, etc).
Is the only difference between server side and non-server side is that when I'm doing it server side, only a subset of my data is in my DOM and if I'm doing it non-server side the whole data is in my DOM, correct?
Regards
I know there are probably a lot threads about this topic, but I need some clarification.
AJAX initially has nothing to do with server side processing of the data right?
So what I want to do is, get the data from my server pass it into the datatable and use all the functionality (sorting, searching, etc).
Is the only difference between server side and non-server side is that when I'm doing it server side, only a subset of my data is in my DOM and if I'm doing it non-server side the whole data is in my DOM, correct?
Regards
This discussion has been closed.
Replies
2) correct. AJAX sourced data pulls in all your data at once, then you use client-side searching, sorting, pagination, etc. server-side sourced DataTables puts these functions on the server side in the case that your data would be too large to effectively deal with on the client side using javascript.
So for example I've got something like this
[code]
$(document).ready(function () {
$('#jugendamtTable').dataTable({
"bProcessing": true,
"sAjaxSource": "/MyAjaxURL"
});
});
[/code]
What I read so far is that I need to return a JSON String. What exactly does my service need to return? Just something like this?
[code]
{ "aaData": [
["data1","data2","data3", ...]
...
]
}
[/code]
if you don't want to pull from a file, you don't need AJAX. you could put the data in an array on the client side javascript (this could be generated by a PHP script if you wish).
http://www.datatables.net/release-datatables/examples/data_sources/js_array.html
I also could read it from a URL which returns a string could I?
Are there any reasons what I should do? (performance or whatever)
Isn't that a bad idea, because u would have the data in the array and redundant in the table also...
I have trouble setting up the method which should return the data.
Does it have the same format as the array in the arrays.txt file, or just JSON format?
It has to be the arrays.txt format :-)
HTML
[code]
$(document).ready(function () {
$('#yourTable').dataTable({
"bProcessing": true,
"sAjaxSource": "/YourController/YourAction",
});
});
Header1
Header1
[/code]
Make sure you have the correct table headers, or specify them in the javascript initializer
C# Code
[code]
public class YourController: Controller
{
public String YourAction()
{
// get your data
// build string like that
// { "aaData": [
// ["Data1","Data2"],
// ["Data1","Data2"]
// ] }
return dataString;
}
}
[/code]