build aoData on the fly
build aoData on the fly
I am very new to DataTables so if this has been beat to death already I am sorry.
My server is ColdFusion and it's standard way to return a query by JSON is this:
{"COLUMNS":["USERID","IS_DELETED","VENDOR_NAME","VENDOR_NUMBER","USERNAME"],"DATA":[[1,null,null,1000,"nbsvendor"],[2,null,"NBS Fall forms test",123,"nbstest"],[3,null,"nbs fall forms test",125,"fall"]]}
The way I understand it an object with two arrays COLUMNS and DATA.
I have not had any luck using "sAjaxSource": "http://10.10.10.76/cfc/datatable4.cfc?methond=myData"
So I tried this:
$(document).ready(function() {
$('#demo').html( '' );
$.ajax({
type: "GET",
url: "/cfc/dataTable2.cfc?method=myData&returnformat=json",
<!---data: dataString,--->
dataType: "json",
success: function(data){
$('#example').dataTable( {
"aaData": [
data.DATA[0],
data.DATA[1],
data.DATA[2]
],
"aoColumns": [
{ "sTitle": data.COLUMNS[0] },
{ "sTitle": data.COLUMNS[1] },
{ "sTitle": data.COLUMNS[2] },
{ "sTitle": data.COLUMNS[3], "sClass": "center" },
{ "sTitle": data.COLUMNS[4], "sClass": "center" }
]
});
},//end success post
error: function(data){
alert('error');
}
});
});
I am not very good at javascript either so I was wondering is there a way to loop over my returned data set to build aaData?
Can you instantiate with something like this? $('#example').dataTable( {aaData,aoColumns});
Thanks in advance for any nudge in the right direction.
My server is ColdFusion and it's standard way to return a query by JSON is this:
{"COLUMNS":["USERID","IS_DELETED","VENDOR_NAME","VENDOR_NUMBER","USERNAME"],"DATA":[[1,null,null,1000,"nbsvendor"],[2,null,"NBS Fall forms test",123,"nbstest"],[3,null,"nbs fall forms test",125,"fall"]]}
The way I understand it an object with two arrays COLUMNS and DATA.
I have not had any luck using "sAjaxSource": "http://10.10.10.76/cfc/datatable4.cfc?methond=myData"
So I tried this:
$(document).ready(function() {
$('#demo').html( '' );
$.ajax({
type: "GET",
url: "/cfc/dataTable2.cfc?method=myData&returnformat=json",
<!---data: dataString,--->
dataType: "json",
success: function(data){
$('#example').dataTable( {
"aaData": [
data.DATA[0],
data.DATA[1],
data.DATA[2]
],
"aoColumns": [
{ "sTitle": data.COLUMNS[0] },
{ "sTitle": data.COLUMNS[1] },
{ "sTitle": data.COLUMNS[2] },
{ "sTitle": data.COLUMNS[3], "sClass": "center" },
{ "sTitle": data.COLUMNS[4], "sClass": "center" }
]
});
},//end success post
error: function(data){
alert('error');
}
});
});
I am not very good at javascript either so I was wondering is there a way to loop over my returned data set to build aaData?
Can you instantiate with something like this? $('#example').dataTable( {aaData,aoColumns});
Thanks in advance for any nudge in the right direction.
This discussion has been closed.