iDeferLoading and aoColumns

iDeferLoading and aoColumns

jeffzzangjeffzzang Posts: 1Questions: 0Answers: 0
edited September 2011 in DataTables 1.8
Hello, I am using DataTables 1.8 and am trying to use the iDeferLoading and aoColumns options at the same time. I basically have 150 records I want to split into 3 pages. I've set the iDisplayLength parameter properly. I want the first load of the page to be done on the server (IE, server produces the table with the first 50 rows of data). I then want to use Ajax to callback to the server and request the rest of the data using JSON when the user pages. This is why I am using the iDeferLoading parameter. The JSON I return will be serialized POJOs (my domain objects), so there may be some nested objects in the response, which is why I am using the aoColumns parameter.

Here is my code:

[code]
$(document).ready(function(){
$("#list_users_table").dataTable({
"iDisplayLength": 50,
"bProcessing": true,
"iDeferLoading": 150,
"bServerSide": true,
"sAjaxSource": "/front/?command=ListUsers",
"aoColumns": [
{ "mDataProp": "firstName" },
{ "mDataProp": "emailAddress.email" },
{ "mDataProp": null },
{ "mDataProp": null },
]
});
});
[/code]

Note, the last two columns are just columns that display "Edit" and "Delete", so I set mDataProp to null. (I think that's what I'm supposed to do)


When I load the page for the first time (no ajax, all server), I'm getting a javascript error:

[quote]
Uncaught TypeError: Cannot set property 'email' of undefined
[/quote]

I am using the minified version, so the line number is somewhat useless to report here I think. If it's more helpful, I can switch over to the non-minified version and report exactly where in the library the error is occurring.

I think the library is trying to use the aoColumns option, but since the first load doesn't have any JSON to operate on, the library cannot get the "email" property. Just speculation, not really sure what's going on behind the scenes. I'm new to this library, so maybe I'm screwing something up.

Anyone else run into similar problems? Many thanks!

Replies

  • tomcleggtomclegg Posts: 1Questions: 0Answers: 0
    edited October 2011
    I have a similar problem: I want an empty cell instead of a JavaScript exception when mDataProp is 'foo.bar.baz' and my ajax source does not always provide foo.bar on every row.

    The error happened at line 6810 of non-minified 1.8.2, in my case.

    Rather than patch jquery.dataTables.js, the slightly-less-awful approach I'm using for now is to copy the two patched functions and a little bit of glue into a fnSkipMissingDataProps() plugin.

    Beware that this has *not* been well tested. I'm hoping a future version of DataTables (or a better suggestion) will make this unnecessary.

    https://gist.github.com/1268111
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Hi tomclegg,

    Thanks very much for the gist - a plug-in is a really nice way of doing this. There have been a couple of requests for something along these lines, so I think this probably is the right thing to do. What I had been thinking was putting a try/catch into the _fnGetObjectDataFn which would return null when an error occurs. That would cause _fnGetCellData to fall into its "default" state which would be to either use null or the default content for the cell. Possibly an error should be logged, or perhaps this should be an optional configuration (since for a power user is very useful, but could be confusing if you are new to using these features).

    Regards,
    Allan
  • davidRamdavidRam Posts: 1Questions: 0Answers: 0
    Hi jeffzzang,

    Did you come up with any solution to your problem?

    I have the same problem and don't understand tomclegg solution.

    Thanks
This discussion has been closed.