How to load related REST resources to display in DataTables
How to load related REST resources to display in DataTables
I'm using TastyPie to serve REST resources and DataTables to display the data in a grid. Some models I want to display in the grid have foreign keys to other models. So I load the JSON data for the models but I still need to retrieve the JSON for the related resources to display.
So let's say I have two models, User, Membership and the latter has a foreign key to the former. I want to view Membership data in the grid so I retrieve the JSON data for memberships. I want to display the username in each row but I only have the resource URI for the user and not the user data. So I need to perform other Ajax requests to get the user data.
If you're still following me, how would I go about doing this with DataTables? The render function available for the columns doesn't provide the ability to perform asynchronous requests - it just expects you to return a string, like so:
"mRender": function(data, type, obj) {
return dateFormat(obj.timestamp, "yyyy-mm-dd HH:MM:ss");
}
Thanks
Answers
I was reading through the docs when I wrote this, but since then, I've discovered this option:
http://datatables.net/examples/advanced_init/row_callback.html
This may work.
I'm still using an older version so I can "fnRowCallback" works nicely.