drup
drup

Reputation: 1157

How to Change datatable default empty table message

I am using datatable to list and sort the results.

This is how i initialized datatable

$('#example1').DataTable({bFilter: false, bInfo: false, paging: false});

It works fine. But i need to change the default table empty message No data available in table to No records found. Please help.

Upvotes: 20

Views: 58993

Answers (3)

Collei Inc.
Collei Inc.

Reputation: 76

Change the default message for empty results in a DataTable on the fly:

    $("#myTable").on('draw.dt', function(){
        $('#myTable .dataTables_empty').html('Your custom message here.');
    });

No need for destroy() and re-initialization, and you can even change the message based upon another page element.

Upvotes: 2

Ajinkya Avinash Aher
Ajinkya Avinash Aher

Reputation: 558

$('#example').dataTable({
    "oLanguage": {
        "sEmptyTable": "My Custom Message On Empty Table"
    }
});

Reference: http://datatables.net/forums/discussion/2327/how-to-localize-the-string-no-data-available-in-table

Upvotes: 46

Robert Groves
Robert Groves

Reputation: 7748

The answer by Ajinkya should still work because the library currently maintains backward compatibility with the old option format, but with more recent versions of the DataTables library (1.10+) you should use:

$('#example').dataTable( {
    "language": {
      "emptyTable": "No data available in table"
    }
} );

See: https://datatables.net/reference/option/language.emptyTable

Also, if you want to customize the info line when the table (or search results are empty):

$('#example').dataTable( {
  "language": {
    "infoEmpty": "No entries to show"
  }
} );

See: https://datatables.net/reference/option/language.infoEmpty

Upvotes: 31

Related Questions