Newbie question - Datatables front-end, Delphi 2010 Datasnap REST back-end

Newbie question - Datatables front-end, Delphi 2010 Datasnap REST back-end

Andy_DAndy_D Posts: 2Questions: 0Answers: 0
edited August 2012 in General
Hi,

I have an existing application which requires a web front-end and Datatables looks like just the thing to get the bulk of the job done. I have a Delphi REST back end which if I call http://localhost/ISAPI/isapitest.dll/datasnap/REST/TServerMethods1/Contacts emits the following JSON :-
[code]
{
"result": [
[
{
"OID": 505,
"Number": "07863281972",
"FirstName": "Joe",
"LastName": "Smith"
},
{
"OID": 506,
"Number": "07868802482",
"FirstName": "Fred",
"LastName": "McCabe"
},
{
"OID": 508,
"Number": "07857665520",
"FirstName": "Andy",
"LastName": "Denton"
}
]
]
}
[/code]

I'm using the following code to instantiate my DataTables instance :-

[code]
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "/ISAPI/ISAPITest.dll/datasnap/rest/TServerMethods1/Contacts",
"sAjaxDataProp": "result[0][0]",
"aoColumns": [
{ "mDataProp": "OID" },
{ "mDataProp": "Number" },
{ "mDataProp": "FirstName" },
{ "mDataProp": "LastName" }
]
} );
} );

[/code]

All that happens is an empty table is displayed with the "Processing.." box for a while, then it just gives up. I'm not that familiar with the whole JS/JQuery stuff but I can't see anything obvious I've done wrong. I've tried setting bServerSide to true, but that doesn't make any difference. Does anyone have any ideas?

Thanks in advance,

Andy

Replies

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    Try changing:

    > "sAjaxDataProp": "result[0][0]"

    to:

    > "sAjaxDataProp": "result.0"

    If that doesn't work, could you run your table through the DataTables debugger and let us know the debug code please.

    Allan
  • Andy_DAndy_D Posts: 2Questions: 0Answers: 0
    Hi Allan,

    That did it! I knew it would be something stupid.

    Thanks very much for your prompt help. It's greatly appreciated. :)

    Andy
  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    It was quite sensible actually :-). However, DataTables doesn't support array syntax, only dotted Javascript object notation. And you on'y needed the first element of the array to get the inner array.

    Good to hear that did the business for you.

    Regards,
    Allan
This discussion has been closed.