Reloading of DataTables

Reloading of DataTables

SashSash Posts: 5Questions: 0Answers: 0
edited May 2011 in General
Great plugin!

Just started using it a few days ago and I can already see the benefits!

I have a general question - I can't seem to wrap my mind around this one.

I am loading some JSON data via ASMX web services. I have defined my aaData and aoColumns and I am rendering them accordingly. This works fine. Now the issue I am having is when attempting to reload DataTables with a new data sources - doesn't allow me to re-initialize DataTable.

To cut the long story short - I am building dynamic reports creation page where a user can essentially build reports based on different views and tables - so essentially the data that I am loading and re-loading into the datatable has to be dynamic.

I have tried a number of different approaches all seem to be failing. Should I first initialize datatables eg.
[code]
function initDataTable() {
TableTools.DEFAULTS.aButtons = ["copy", "csv", "xls"];

var settings = {
"bJQueryUI": true,
"bProcessing": true,
"bRetrieve": true,
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "/Scripts/datatables/media/swf/copy_cvs_xls_pdf.swf"
}
}
oTable = $("#datatable").dataTable(settings);
}
[/code]

and then in my other code where I call my reports based on reportId:

[code]
function getReport(reportId) {
$.post('/Services/Reporting.asmx/GetReport', { reportId: reportId }, function (response) {
var json = $.parseJSON(response.text);
alert(response.text);
oTable.fnReloadAjax(json);
// var settings = {
// "bJQueryUI": true,
// "bProcessing": true,
// "bRetrieve": true,
// "sDom": 'T<"clear">lfrtip',
// "oTableTools": {
// "sSwfPath": "/Scripts/datatables/media/swf/copy_cvs_xls_pdf.swf"
// },
// "aaData": json.aaData,
// "aoColumns": json.aoColumns
// }

// oTable = $("#datatable").dataTable(settings);

});
}
[/code]

the fnReloadAjax isn't seem to be displaying my data.

Now, I do understand that when loading data via ajax, it only eveluates aaData, so in my previous examples I was able to get it to work as you can see in the commented out bits.

My problem is that I just don't know how to re-initialize the table and re-create it with a totally different view/datasource.

Also I have one more issue at hand - I keep getting asSorting is null or not an object - is this related to the same issue?

Thank you in advance.
This discussion has been closed.