jQuery datatables dont show table if have'nt data

jQuery datatables dont show table if have'nt data

tuxworldstuxworlds Posts: 6Questions: 0Answers: 0
edited May 2013 in General
i'm using jquery datatabls with server side fetch data, my problem is when table of data is empty datatables hide table and dont show that, i want to show table with no any data on table message, how to have this option?
[code]
oTable_topics =$('#showTopics').dataTable({
"bLengthChange": false,
"bStateSave": true,
"iDisplayLength": 12,
"bScrollCollapse": true,
"bJQueryUI": true,
"bAutoWidth": false,
"sAjaxSource": "server_processing.php",
"sPaginationType": "full_numbers",
"bProcessing": true,
// "fnCreatedRow": function( nRow, aData, iDataIndex ) {
// $('td:eq(5)', nRow).html("");
// },
"fnDrawCallback": function(oSettings) {
clickRowHandler_topics();
if ( oSettings.aiDisplay.length == 0 )
{
return;
}
var nTrs = $('tbody tr', oSettings.nTable);
var iColspan = nTrs[0].getElementsByTagName('td').length;
var sLastGroup = "";
for ( var i=0 ; i

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Use fnDrawCallback to get if there is any data in the table - if not, just hide it with display: none.

    Allan
  • psharppsharp Posts: 39Questions: 0Answers: 0
    If you wish to have the table display , but without any data it's pretty simple.

    In your model (or whatever you call your transport), check for an empty result set there.
    If you have no data to return from your query, simply return a blank record in aaData, like so:
    [code]
    if (!isset($return['aaData']) ) {$return['aaData'][] = array('','', ... repeat for each field expected); }
    [/code]

    Easy peasy.
This discussion has been closed.