reload/redraw data tables
reload/redraw data tables
Hello, I have a big problem.
I read this discussion http://datatables.net/forums/comments.php?DiscussionID=573 and I can not redraw with new data my table.
I have in html a link: redraw
and js:
[code]
$('.dataTable').dataTable({
// old data
"sAjaxSource": "ajax_handler.html",
"iServerAction": "todo",
"fnServerData": fnDataTablesPipeline
})
function redraw(){
oTable.fnStandingRedraw({
"sEcho": 0,
"iTotalRecords": 38,
"iTotalDisplayRecords": 5,
// new data
"aaData": [
["2010-02-01 15:21:29","test1","ddd","7"],
["2010-02-01 15:21:29","test2","ccc","7"],
["2010-01-30 09:21:01","test3","bbb","7"],
["2010-01-30 09:21:01","test4","aaa","7"],
]
});
}
[/code]
w would like to change data on aaData when I click link redraw.
How can I do this?
I read this discussion http://datatables.net/forums/comments.php?DiscussionID=573 and I can not redraw with new data my table.
I have in html a link: redraw
and js:
[code]
$('.dataTable').dataTable({
// old data
"sAjaxSource": "ajax_handler.html",
"iServerAction": "todo",
"fnServerData": fnDataTablesPipeline
})
function redraw(){
oTable.fnStandingRedraw({
"sEcho": 0,
"iTotalRecords": 38,
"iTotalDisplayRecords": 5,
// new data
"aaData": [
["2010-02-01 15:21:29","test1","ddd","7"],
["2010-02-01 15:21:29","test2","ccc","7"],
["2010-01-30 09:21:01","test3","bbb","7"],
["2010-01-30 09:21:01","test4","aaa","7"],
]
});
}
[/code]
w would like to change data on aaData when I click link redraw.
How can I do this?
This discussion has been closed.
Replies
- fnStandingRedraw doesn't accept any parmaeters - so sEcho and all that stuff will be completely ignored
- The pipeline function will only have any effect with server-side processing - it's probably quite dangerous to use with just an Ajax sourced data
- sEcho etc mean nothing to DataTables other than for server-side processing
- iServerAction will be completely ignored on initialisation because DataTables doesn't recognise it (unless you've added code to do it)
I'm not sure what you are actually trying to do here - sorry. You want to reload the table with new data, and that data is not from sAjaxSource? Then use fnClear and fnAddData ( http://datatables.net/api )
Allan
Yes data is from sAjaxSource (I wrote only sample data which I received from ajax request).
I wolud like to redraw table with new data when I click a link.
PS. I trying fnReloadAjax but I want to get data with new parametr for example:
sEcho=1&iColumns=4&sColumns=&iDisplayStart=0&iDisplayLength=5&sSearch=&bEscapeRegex=true&sSearch_0=&bEscapeRegex_0=true&bSearchable_0=false&sSearch_1=&bEscapeRegex_1=true&bSearchable_1=true&sSearch_2=&bEscapeRegex_2=true&bSearchable_2=false&sSearch_3=&bEscapeRegex_3=true&bSearchable_3=false&iSortingCols=1&iSortCol_0=0&sSortDir_0=desc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false
this request response me 40 aaData sub arrays - this is ok
my new request should be almost the same (when I click link):
sEcho=1&iColumns=4&sColumns=&iDisplayStart=0&iDisplayLength=5&sSearch=&bEscapeRegex=true&sSearch_0=&bEscapeRegex_0=true&bSearchable_0=false&sSearch_1=&bEscapeRegex_1=true&bSearchable_1=true&sSearch_2=&bEscapeRegex_2=true&bSearchable_2=false&sSearch_3=&bEscapeRegex_3=true&bSearchable_3=false&iSortingCols=1&iSortCol_0=0&sSortDir_0=desc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&startDate=2010-01-30&endDate=2010-02-02
this request should response me 5 aaData sub arrays
[code]
$.fn.dataTableExt.oApi.fnChangeAjaxData = function(oSettings, sNewSource)
{
oSettings.sAjaxSource = sNewSource;
this.fnClearTable(this);
this.oApi._fnProcessingDisplay(oSettings, true);
}
[/code]
$('#posDatatable').dataTable().fnChangeAjaxData(mySettings, "http://www.go.com/fooo");
With your function i get an ultra weird Ajax request in terms of URL. Instead of my http://www.go.com/fooo, it will call my old URL with some "object" strings in there.
Still cant believe that there is no easy way to simply refresh the table with a different AJAX url. Furthermore i dont know how to know if i should create the dataTable in my handler or if i should just call some refresh/reload function.
Is there a way to know if the datatable is already initialized on the HTML element (on the css selector) ?
Marc