How to show empty data message in Datatables

2019-01-16 15:55发布

Suppose i get empty data from server sometimes, i want to display No Data found message in DataTables?. How is this possible?

5条回答
我只想做你的唯一
2楼-- · 2019-01-16 15:56

If you want to customize the message that being shown on empty table use this:

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

Since Datatable 1.10 you can do the following:

$('#example').DataTable( {
    "language": {
        "emptyTable":     "My Custom Message On Empty Table"
    }
} );

For the complete availble datatables custom messages for the table take a look at the following link reference/option/language

查看更多
仙女界的扛把子
3楼-- · 2019-01-16 16:02

Late to the game, but you can also use a localisation file

DataTable provides a .json localized file, which contains the key sEmptyTable and the corresponding localized message.

For example, just download the localized json file on the above link, then initialize your Datatable like that :

$('#example').dataTable( {
    "language": {
        "url": "path/to/your/json/file.json"
    }
});

IMHO, that's a lot cleaner, because your localized content is located in an external file.

This syntax works for DataTables 1.10.16, I didn't test on previous versions.

查看更多
ら.Afraid
4楼-- · 2019-01-16 16:08

Later versions of dataTables have the following language settings (taken from here):

  • "infoEmpty" - displayed when there are no records in the table
  • "zeroRecords" - displayed when there no records matching the filtering

e.g.

$('#example').DataTable( {
    "language": {
        "infoEmpty": "No records available - Got it?",
    }
});

Note: As the property names do not contain any special characters you can remove the quotes:

$('#example').DataTable( {
    language: {
        infoEmpty: "No records available - Got it?",
    }
});
查看更多
劳资没心,怎么记你
5楼-- · 2019-01-16 16:13

By default the grid view will take care, just pass empty data set.

查看更多
Summer. ? 凉城
6楼-- · 2019-01-16 16:21

It is worth noting that if you are returning server side data - you must supply the Data attribute even if there isn't any. It doesn't read the recordsTotal or recordsFiltered but relies on the count of the data object

查看更多
登录 后发表回答