Classic ASP and datatables usage
Classic ASP and datatables usage
akellorich
Posts: 3Questions: 0Answers: 0
Hello, I am a developer in classic ASP and was wondering how I could use ASP to populate my datatable for reporting and search functionality. I was assuming DataTables would accept primitive JSON data in the format with the example [code] [{"CategoryName":"Expenses","Id":1,"CategoryId":1,"GroupCode":"2210200","GroupName":"Communication"},{"CategoryName":"Expenses","Id":2,"CategoryId":1,"GroupCode":"2210300","GroupName":"Domestic travel and Subsistence"}] [/code] but apparently it's not working. Any Ideas would be helpful.
This discussion has been closed.
Replies
It will indeed :-). You need to tell DataTables two things:
1. To expect a plain array of data form the Ajax source - done by setting sAjaxDataProp to be an empty string (i.e. "").
2. Use mDataProp to tell each column which property to populate the table with from the JSON feed: http://datatables.net/blog/Extended_data_source_options_with_DataTables
Allan
the asp code is as follows
[code]
$(document).ready(function(){
//$('#messages').hide()
$('#successhead').hide()
$('#errorhead').hide()
$('button').button()
$('#positionid').val(0)
$('#positionname').val("")
$('#positiondetails').hide()
$('#positions').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": '<"H"Tfr>t<"F"ip>',/**/
//"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "results.asp?id=53",
"sAjaxSource": "",
"aoColumns": [
{ "mDataProp": "PositionId" },
{ "mDataProp": "PositionDescription" },
{ "mDataProp": "DateAdded" },
{ "mDataProp": "AddedBy" }
],
"oTableTools": {
"sSwfPath": "media/copy_csv_xls_pdf.swf",
"aButtons": [ "xls", "print","pdf" ]
}
})
})
[/code]
And the output generated from the asp search is
[code]
[{"PositionId":"1","PositionDescription":"Program","DateAdded":"6/25/2012 6:07:28 PM","AddedBy":"Admin"},{"PositionId":"2","PositionDescription":"Program Coordinator","DateAdded":"6/25/2012 6:30:48 PM","AddedBy":"Admin"},{"PositionId":"3","PositionDescription":"District Agricultural Officer","DateAdded":"6/25/2012 6:31:47 PM","AddedBy":"Admin"},{"PositionId":"4","PositionDescription":"Provincial Agricultural Officer","DateAdded":"6/25/2012 6:32:01 PM","AddedBy":"Admin"},{"PositionId":"5","PositionDescription":"CIG Trainer","DateAdded":"6/25/2012 6:34:48 PM","AddedBy":"Admin"},{"PositionId":"6","PositionDescription":"Test Test Test","DateAdded":"6/25/2012 6:49:09 PM","AddedBy":"Admin"}]
[/code]
What could possibly be the matter?
Regards
Richard
Allan
Sorry for the long absence the code generated is uracim
Please assist
Thanks again