Datatable not rend JSON from server

Datatable not rend JSON from server

lastcowlastcow Posts: 1Questions: 0Answers: 0
edited May 2012 in DataTables 1.9
I have a json send from server like following:
[code]
[
{"user":{"firstname":null,"lastname":null,"mrn":null,"username":"zhangyiddt"}},
{"user":{"firstname":null,"lastname":null,"mrn":null,"username":"lastcow"}}
]
[/code]
and i have html as following (haml version):
%table.datatable#patientlist
%thead
%tr
%th
Patient first name
%th
Patient last name
%th
Username
%th
MR Number
this is basically with 4 column header.

and here is my js:
[code]
$('#patientlist').dataTable({
bProcessing: false,
sAjaxSource: '/administration/allpatiens.json',
//sAjaxDataProp: 'object'
aoColumns:[
{mDataProp:'firstname'},
{mDataProp: 'lastname'},
{mDataProp: 'username'},
{mDataProp: 'mrn'}
],
success: function(json){

},
sPaginationType: 'full_numbers',
sDom: '<"header-table"lf>rt<"footer-table"ip>',
oLanguage: { oPaginate: {
sFirst: '<',
sPrevious: '(',
sNext: ')',
sLast: '>'
}},
fnInitComplete: function(t){
var $table = $(t.nTable), $head = $table.prev();
$head.find('select').uniform();

$head.find('.dataTables_length label').wrapInnerTexts();
$head.find('.dataTables_filter label').wrapInnerTexts();
$head.find('input[type=text]').wrap('').parent().prepend('' + createIcon('magnifier') + '');
$table.find('.sorting, .sorting_asc, .sorting_desc').wrapInner($('')).find('.parentsort').append('');
}
});
[/code]

when I load the page, i can see json download from server, but table always showing 'loading...', is there any wrong with json format?

please help.

Thanks, :)

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    read the "Example JSON return" section to get the right format that datatables expects
    http://www.datatables.net/usage/server-side
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    Also worth reading this blog post, as DataTables can read almost any JSON format with this method: http://datatables.net/blog/Extended_data_source_options_with_DataTables

    Allan
This discussion has been closed.