How can I prevent jQuery dataTable plugin from adding rows and messages when there is no data

Our product owner would like our empty tables to display only the table title when there is no data in the table. I can not stop the dataTable from creating a line with the message "empty ...".

Here is the code that I use to initialize the dataTable. I know some things are wrong here. I experimented. :)

$('#InBox').dataTable({ "bFilter": false, "bPaginate": false, "bLengthChange": false, "bInfo": false, "oLanguage": { "sEmptyTable": '', "sInfoEmpty": '' } }); 

Here is the code I tried to put in the initTableTable function, but I'm not sure how to make it work.

 /* Table is empty - create a row with an empty message in it */ var anRows[0] = document.createElement('tr'); if (typeof oSettings.asStripClasses[0] != 'undefined') { anRows[0].className = oSettings.asStripClasses[0]; } var nTd = document.createElement('td'); nTd.setAttribute('valign', "top"); nTd.colSpan = oSettings.aoColumns.length; nTd.className = oSettings.oClasses.sRowEmpty; if (oSettings.fnRecordsTotal() > 0) { if (oSettings.oLanguage.sZeroFilterRecords.indexOf("_MAX_") != -1) oSettings.oLanguage.sZeroFilterRecords = oSettings.oLanguage.sZeroFilterRecords.replace("_MAX_", oSettings.fnRecordsTotal()); nTd.innerHTML = oSettings.oLanguage.sZeroFilterRecords; } else { nTd.innerHTML = oSettings.oLanguage.sZeroRecords; } anRows[iRowCount].appendChild(nTd); 

Dan

+8
jquery datatable
source share
5 answers

try it

 $('#InBox').dataTable({ "bFilter": false, "bPaginate": false, "bLengthChange": false, "bInfo": false, "oLanguage": { "sEmptyTable": '', "sInfoEmpty": '' }, "sEmptyTable": "There are no records", }); 

otherwise you can try this

 $('#InBox').dataTable({ "bFilter": false, "bPaginate": false, "bLengthChange": false, "bInfo": false, "oLanguage": { "sEmptyTable": '', "sInfoEmpty": '' } }); $('.dataTables_empty').html("No record found."); 
+8
source share

An old post, but for the sake of people using search engines looking for the right answer, here's how I did it.

Delete or comment out the following line from the dataTables source:

 anRows[iRowCount].appendChild(nTd); 

In the shortened version, perform a search and delete:

 b[i].appendChild(c); 
+3
source share

If you want to delete your object connected to the connected plugin, you can try this workaround:

 $('.dataTables_empty').parent().parent().remove(); 
+3
source share

You can customize the DataTable plugin using oLanguange:

 "oLanguage": { "sZeroRecords": "-Put customized text-", "sEmptyTable": "-Put customized text-" } And if you want to remove those, just put these components into null: "oLanguage": { "sZeroRecords": '', "sEmptyTable": '' } 

Hope this helps!

+2
source share

The most recent way to hide messages is with the option

 $('#loggedMessages').DataTable({ "language": { "emptyTable": ' ', "zeroRecords": ' ' } }); 
+1
source share

All Articles