Server-side processing JSON response with no aaData
Server-side processing JSON response with no aaData
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]
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]
This discussion has been closed.
Replies
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