stefun stefun - 20 days ago 9
jQuery Question

Show button if data table rows are empty

We want to show

ADD User
button or link in place of "No matching records found" message if we get 0 records. Also we need pass searched id with the link

How we can implement this.


ADD User link

I was trying with :

"fnDrawCallback": function(retObj) {



var userTable=$('#allUsers').DataTable({
"processing": true,
"serverSide": true,
'responsive': true,"stripeClasses": [ 'odd-row', 'even-row' ],
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [1,2,3,4,5] }
"ajax": {
url: "users_list.php",
type: 'GET',
data: userData
"fnDrawCallback": function(retObj) {
console.log("0 records");
"language": {
"infoFiltered": "",
search: "_INPUT_",
searchPlaceholder: "Search...",
"emptyTable": '<a href="/path/' + 1 + '">BOOK THIS COURSE</a>'
"pageLength": 10

still getting "No matching records found" message.


Use language.emptyTable option to define a message when there are no records in the table.

For example:

var table = $('#example').DataTable({
   'language': {
      'emptyTable': '<a href="/path/' + 1 + '">Add new user</a>'

See this example for code and demonstration.

Use can also use language.zeroRecords option to define a message when the table is empty due to filtering.