Server-side processing JSON response with no aaData

Server-side processing JSON response with no aaData

jamiepjamiep Posts: 2Questions: 0Answers: 0
edited February 2012 in General
I'm using EclipseLink MOXy on the server-side to marshal some JPA entities into JSON.

This works fine as long as there are results to return, however if there are no results then instead of returning an empty array in aaData, it returns no aaData at all.

I have tried to coerce it into marshalling a null or empty list into an empty array - with no success.

Is there any way of getting DataTables to treat a null/missing property the same as it would if aaData was an empty array?

I tried sDefaultContent, with no joy either:

[code]
$('#tbl_mndb_pending').dataTable( {
'bProcessing': true,
'bServerSide': true,
'sAjaxSource': tableSrcURL,
'bJQueryUI': true,
'sDom': '<"H"Tfr>t<"F"ip>',
'iDisplayLength': 10,
'aLengthMenu': [[10, 25, 50, -1], [10, 25, 50, "All"]],
'aaSorting': [[5, 'desc']],
'oTableTools': {
'sSwfFile': 'media/plugin/datatables/media/swf/copy_cvs_xls_pdf.swf',
'aButtons': [
'print', 'copy', 'csv', 'xls', 'pdf',
{
'sExtends': 'collection',
'sButtonText': 'Save',
'aButtons': [ 'print', 'csv', 'xls', 'pdf' ]
}
]
},
'fnServerData': function(sSource, aoData, fnCallback) {

'fnDrawCallback': function() {

'aoColumnDefs': [
{ 'sDefaultContent': '-', 'aTargets': [0], 'mDataProp': 'crType', },
{ 'sDefaultContent': '-', 'aTargets': [1], 'mDataProp': 'crRef', },
{ 'sDefaultContent': '-', 'aTargets': [2], 'mDataProp': 'description', 'sWidth': '34%', 'sClass': 'clickable' },
{ 'sDefaultContent': '-', 'aTargets': [3], 'mDataProp': 'contactName', 'sWidth': '15%' },
{ 'sDefaultContent': '-', 'aTargets': [4], 'mDataProp': 'crStatus', },
{ 'sDefaultContent': '-', 'aTargets': [5], 'mDataProp': 'receivedDate', 'sWidth': '15%' },
{ 'sDefaultContent': '-', 'aTargets': [6], 'mDataProp': 'status', 'sClass': 'editable-status' },
{ 'sDefaultContent': '-', 'aTargets': [7], 'mDataProp': 'reason', 'sClass': 'editable-reason' }
]
[/code]

Replies

  • chansonchanson Posts: 5Questions: 0Answers: 0
    Have you tried setting "sAjaxDataProp": "" ?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    DataTables in server-side processing mode always expects there to be an array for the data container (the name of which can be changed using sAjaxDataProp as chanson points out - although an empty string wouldn't work in this case since an object must be returned with sEcho etc).

    As such, what you would need to do use your fnServerData function to check for the return from the server. If there is no aaData, just add one to the data (an empty array), and that will do it.

    Allan
This discussion has been closed.