Topic: RailsCast#340 - JSON not well formed for dataTables
In the RailsCast#340 Datatables, it appears that the JSON array returned is not what is expected by DataTables.
Let say for a model User where mapping returns user.id, user.last_name, user.first_name, user.email the returned JSON is
aaData: [[1, DOE, John, doe@example.com,…],[7, BAXTER, Bill, baxter@example.com],[15, BROWN, Bob, brown@example.com],...]wich is a one dimension array, and the 2 dimensions arraay expected by DataTables (for the aaData part) should be for the same set of data
aaData: [{"id":1, "last_name":"DOE", "first_name":"John", "email":"doe@example.com",…},{"id":7, "last_name":"BAXTER", "first_name":"Bill", "email":"baxter@example.com"],{"id":15, "last_name":"BROWN", "first_name":"Bob", "email":"brown@example.com"},...]So if it displays well in the example provided it throws error when filtering server-side with an error
"JSON data from server could not be parsed. This is caused by a JSON formatting error"
Is there anybody who knows how to return the well formatted JSON ?
Any help would be appreciate
Last edited by anso (2013-03-02 14:55:48)