Created
October 26, 2012 21:35
-
-
Save elmarcoh/3961705 to your computer and use it in GitHub Desktop.
Using Tastypie as an Ajax Source for DataTables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#participantes-table').dataTable({ | |
bProcessing: true, | |
bServerSIde: true, | |
sAjaxSource: "/path/to/your/tastypie/api/list/objects/?format=json", | |
sAjaxDataProp: "objects", | |
aoColumns: [ | |
// Put the resource name that corresponds to each table column | |
{'mData': "your"}, | |
{'mData': "columns"}, | |
], | |
fnServerData: function(source, oaData, callback, settings) { | |
settings.jqXHR = $.get( | |
source, | |
function(data){ | |
// Magic happens here! tastypie provides the data but | |
// stupid dataTables requires it to have stupid names | |
data.echo = oaData.echo; | |
data.iTotalRecords = data.meta.total_count; | |
data.iTotalisplayRecords = data.meta.limit; | |
console.debug(data); | |
console.debug(callback); | |
callback(data); | |
}, | |
'json') | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a LOT for this snippets. I beleive DataTable and Tastypie are really great ! Wonder how other people do, actually :)
The previous answers were not working for me. Here is minor modification of what I ended-up. I activated sorting and searching as well.