Bug found in ajax mode

Bug found in ajax mode

matthieucanmatthieucan Posts: 5Questions: 0Answers: 0
edited April 2014 in Bug reports
Hi,
I'm using Datatables 1.9.
When I do this:

[code]



$(document).ready(function() {
$('#res').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/rest/status/json/custom_view/?viewname=foo"
} );
} );

[/code]

I get the error Uncaught TypeError: Cannot read property 'asSorting' of undefined.

However, with

[code]



$(document).ready(function() {
$('#res').dataTable( {
"aaData": [
[
"google.com",
"HTTP",
]
],
"aoColumns": [
{
"sTitle": "host_name"
},
{
"sTitle": "description"
}
]
} );
} );

[/code]

It works like a charm. Obviously, the same content is delivered through "/rest/status/json/custom_view/?viewname=foo".

Any pointer? Is that a bug?

Thanks.

Replies

  • indymxindymx Posts: 63Questions: 3Answers: 0
    Did you validate your json?
  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    I rather suspect you don't have any columns defined in your HTML. Therefore, you need to use aoColumns.sTitle to tell DataTables what columns to create.

    So not a bug here I think.

    Allan
  • matthieucanmatthieucan Posts: 5Questions: 0Answers: 0
    I didn't validate my json, since it works in one of the cases.
    I don't have columns defined in my html for a simple reason: I don't know the number of columns in advance. And it *works* in the 2nd case, without defining columns either.
    Thoughts?
  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    Not sure what you mean by not defining the columns in the second case, you clearly have in the aoColumns array .

    If you don't know the columns in advance you need to make the Ajax request yourself and then populate either the HTML or aoColumns with the information about the columns. DataTables itself currently does not dynamically create columns.

    Allan
  • matthieucanmatthieucan Posts: 5Questions: 0Answers: 0
    The problem is not here, the ajax request does return aoColumns and aaData.

    The fact here is: for exactly the same content (in one case embedded in code, in the other case delivered by ajax), one program works like a charm and the other one doesn't.
  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    > the ajax request does return aoColumns and aaData.

    Yes, but DataTables doesn't use the aoColumns object in the return. There is nothing in the documentation to indicate that it will.

    I fully accept that it should, and it will in future versions, but it doesn't at the moment.

    Allan
  • matthieucanmatthieucan Posts: 5Questions: 0Answers: 0
    That's a pitty. Do you maybe know if this feature is planned for the next release?
  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    I haven't yet firmed up my planned for v1.11, so it might, it might not! It certainly won't be in v1.10 which is almost ready for release and new features aren't being accepted into it now.

    Allan
  • matthieucanmatthieucan Posts: 5Questions: 0Answers: 0
    Ok, thanks for the information! Good luck with the release :)
This discussion has been closed.