json object array as aData param

json object array as aData param

dt_matthewsdt_matthews Posts: 6Questions: 0Answers: 0
edited April 2009 in General
Hi

I have an asp.net page using the following code where [result] is an object collection returned from a WCF service. When I run the data doesnt appear to be parsed by the plug-in, the array has 96 records in it but the pagination / footer only says 1 record.

-=-=-
$('#' + this._tblBookingHistoryID).dataTable(
{
"aData": result,
"bPaginate": true,
"bProcessing": true
});
-=-=-=

Any help much appreciated!

regards,
dan

Replies

  • dt_matthewsdt_matthews Posts: 6Questions: 0Answers: 0
    edited April 2009
    my Collection is a List<> , does it need to be returned from my web service as some other (json string??)
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi dt_matthews,

    You are passing DataTables the Javascript variable "result" as an array of arrays to use. You can see an example of using aData here: http://datatables.net/examples/example_dynamic_creation.html

    So if "result" is actually an ASP.NET List, then you will need to output it as a string in the page, such that the web-browsers Javascript engine will pick it up as a JS array. Remember the web-browser doesn't know anything about ASP.

    Allan
  • dt_matthewsdt_matthews Posts: 6Questions: 0Answers: 0
    edited April 2009
    hi allan,

    Apologies but I'm not clear on how I would build the array in the required notation, I have tried using a JSON Serialiser and also a string object array to no avail

    My service, called via Ajax, returns a IList<> of objects which ajax correctly interprets as a set of JSON objects, I am not clear how that JSON collection needs to be manipulated so that your plugin can consume it - I'm not familiar with the notation cited in you last posit for aaData, its not JSON is it a custom js array of your design (an array of string arrays?) ?

    cheers,
    dan
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi Dan,

    I'm afraid I've not really used ASP.NET much, so I'm shooting in the dark here... But basically what you need the output to look like is:

    [code]
    [
    [ 'col1, row 1', 'col2, row 1', 'col3, row 1' ],
    [ 'col1, row 2', 'col2, row 2', 'col3, row 2' ],
    [ 'col1, row 3', 'col2, row 3', 'col3, row 3' ]
    ]
    [/code]

    Can you perhaps post an example of what it is actually outputing - or even better a link to a page showing the problem?

    Thanks,
    Allan
  • dt_matthewsdt_matthews Posts: 6Questions: 0Answers: 0
    edited April 2009
    Hi Allan,

    I have got it working by parsing the collection returned from the service and building a custom js array per the aaData sample.

    Thanks for your help.
    I'm looking forward to exploring more of the plugin now.
    Might it be worth considering allowing the supply of the datasource as a JSON object as I obviously doing extra processing from JSON to an array which I suppose, if the dataset got very large, might prove a bit of a perf. hit.

    cheers,
    dan
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi Dan,

    Good to hear you got it going. Perhaps you could supply a sample of the JSON output from a datasource? I don't know what formatting it currently takes.

    Thanks
    Allan
This discussion has been closed.