aaData and deep property reading

aaData and deep property reading

steve_at_ventussteve_at_ventus Posts: 18Questions: 5Answers: 0
edited May 2011 in DataTables 1.8
Allan,

First of all, thank you for your work on this fantastic tool. Here's my scenario:

Typically, in the scope of the application I'm working on, I don't use sAjaxSource in favor of aaData because we have a standard JSON format we adhere to for our application (status codes as well as payload), and because sometimes I will feed more than one dT from a single ajax call.

Perhaps prematurely, I updated to 1.8b3 excitedly, as I saw a few features that would be really useful:
1) sAjaxDataProp and,
2) deep property reading
(also excited about deferred DOM, but not relevant to this problem)

I thought that maybe using the two together, I could feed our standard JSON format directly into dataTables. But then I realized that I still need to be checking the status of my replies, so sAjaxSource still isn't for me.

So my question is this: Does dataTables 1.8b3 support using deep property reading on aaData sourced from javascript? All of my current attempts yield this error:
DataTables warning (table id = 'myTableId'): Requested unknown parameter '0' from the data source for row 0

In this case I'm using a very limited sDom, and only a few options (jqui, iDisplayLength, pagination). I can email you specific code examples if you like, but the app is proprietary and unreleased, so I cannot post code publicly.

fwiw: tested in chrome stable, chrome canary, ff4, ff5 (both ff versions with firebug 1.7.x)

Thanks,

-steve

Replies

  • steve_at_ventussteve_at_ventus Posts: 18Questions: 5Answers: 0
    also, jquery 1.6.1 from google cdn (tried 1.5.2 as well, same issue)

    -steve
  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin
    > So my question is this: Does dataTables 1.8b3 support using deep property reading on aaData sourced from javascript?

    Yes :-). Basically both Ajax source and aaData path through the same path of the DataTables code (_fnAddData), so deep property reading should work well with aaData. If you are getting an error saying it can't read property 0, then DataTables is used it's default index search of the data source. Can you show me what you initialisation code looks like?

    > But then I realized that I still need to be checking the status of my replies, so sAjaxSource still isn't for me.

    I plan to do something about that for the next beta - attaching the XHR handle jQuery provides to the settings object so you can access it in fnInitComplete / fnDrawCallback :-). That will be the next commit...

    Regards,
    Allan
  • steve_at_ventussteve_at_ventus Posts: 18Questions: 5Answers: 0
    [code]
    $('#tickets_active_table').dataTable({

    "aaData": response,
    "bProcessing": true,

    "aoColummDefs": [
    {
    "mDataProp": "ticket.ticketId",
    "aTargets": [0]
    },
    {
    "mDataProp": "custName",
    "aTargets": [1]
    }
    ],

    "sDom": 't<"dataTables_footers_dash"ip>',

    "bPaginate": true,
    "sPaginationType": "full_numbers",
    "iDisplayLength": 10,

    "bAutoWidth": false,
    "bJQueryUI": true,

    });
    [/code]

    The following is the value of response that is being passed (array of nested objects, but only one in this simple case)
    [code]
    [
    {
    "ticket": {
    "ticketId": "ticketid",
    "escLevel": "esclevel",
    "status": "ticketstatus",
    "secondaryStatus": "secstatus"
    },
    "custName": "pretend customer",
    "site": {
    "siteName": "siteName",
    "street": "123 any st",
    "street2": "unit 2",
    "city": "city",
    "state": "ST",
    "zip": "zip",
    "country": "usa",
    "phone": "232-545-5465"
    },
    "unit": {
    "host": "hostname",
    "status": "UP",
    "srvcLvl": "NDB"
    },
    "svcType": "Cellular",
    "last": {
    "agent": "agent",
    "time": "12345123"
    },
    "time": {
    "totalInteraction": "231231241",
    "down": "2132131",
    "sla": "232131",
    "slaUp": "12312"
    }
    }
    ]

    [/code]
  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin
    Heh - that had me completely confused for a little bit there - it's all fine apart from this:

    [code]
    aoColummDefs
    [/code]
    it should be:
    [code]
    aoColumnDefs
    [/code]
    :-)

    With that change there is still a little Javascript error when running the table though - you've got bProcessing:true, but no 'r' in sDom - so there is no processing element to show or hide - which throws an error. Removing the bProcessing or adding 'r' into sDom will fix it.

    Allan
  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin
    I've just committed a small change to the DataTables 1.8 development code which results in the XHR object returned from $.ajax() being attached to a parameter jqXHR in the table's settings object. That means in fnDrawCallback you can access the XHR directly:

    [code]
    "fnDrawCallback": function ( oSettings ) {
    console.log( oSettings.jqXHR );
    }
    [/code]
    Useful if you want to use the XHR for more than just DataTables stuff :-). This latest change is available in the "nightly" here: http://datatables.net/download/

    Allan
  • steve_at_ventussteve_at_ventus Posts: 18Questions: 5Answers: 0
    Allan,

    Thank you so much, both for the original addition of the features and for your quick response. I'm sort of embarrassed to have wasted your time on a typo :P

    Thanks also for the addition of the jqXHR passthrough, I'm looking forward to grabbing a copy and playing with it. I see potential to reduce somewhat redundant xhrs used to pipe data to DataTables and other (graphing) libraries to the same page.

    Looking forward to seeing what's next!

    -steve
  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin
    Not a problem at all - hope you enjoy continuing to use DataTables :-)

    Regards,
    ALlan
This discussion has been closed.