IE errors on a subgrid - bad JSON formatting?

IE errors on a subgrid - bad JSON formatting?

justStevejustSteve Posts: 49Questions: 8Answers: 1
edited December 2009 in General
I'm viewing a 'Grid-within-Grid' table - the initial page works fine - when a subgrid is unfolded IE tosses a javascript alert - "added data does not match number of known columns" - all works fine for firefox.

Searching on IE here i find there is a report that FF is more tolerant of malformed JSON than IE but I don't see anything clearly wrong (a firebug screenshot at http://screencast.com/t/ODk0YzI5Y)

I'm pulling data from a .net MVC project and wonder if perhaps the way JSON is serialized is the root cause here.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi justSteve,

    From your screenshot, the aaData array actually contains objects etc as well as just raw data. What datatables expects is:

    [code]
    {
    aaData: [
    [
    "1",
    "2",
    "3"
    ],
    [
    "4",
    "5",
    "6"
    ]
    ]
    }
    [/code]

    So I think you need to remove the objects that are being output, and just fire out a basic 2D array.

    Note also that the inner arrays must each have the same length as the number of columns in the table, otherwise you will get the alert() that you are seeing.

    Regards,
    Allan
  • justStevejustSteve Posts: 49Questions: 8Answers: 1
    Thankx. So the fact that this works for FF but not IE owes to FF's incorrect handling of JSON format?
  • justStevejustSteve Posts: 49Questions: 8Answers: 1
    actually...my error turned out to be caused by the same 'trailing comma' problem reported elsewhere:

    //order date
    {"sWidth": "40%" },

    to:

    //order date
    {"sWidth": "40%" }

    fixed the problem for IE.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi justSteve,

    Yup - that trailing comma is a real nuisance. I can't understand why Firefox allows it... But good that you got it working :-)

    Regards,
    Allan
This discussion has been closed.