How to show empty data message in Datatables

前端 未结 7 1448
感动是毒
感动是毒 2020-12-07 20:04

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

7条回答
  •  我在风中等你
    2020-12-07 20:31

    This is a just a nice idea. that, you can Add class in body, and hide/show table while there is no data in table. This works perfect for me. You can design custom NO Record Found error message when there is no record in table, you can add class "no-record", and when there is 1 or more than one record, you can remove class and show datatable

    Here is jQuery code.

    $('#default_table').DataTable({
    
        // your stuff here
    
        "fnFooterCallback": function (nRow, aaData, iStart, iEnd, aiDisplay) {
            if (aiDisplay.length > 0) {
                $('body').removeClass('no-record');
            }
            else {
                $('body').addClass('no-record');
            }
        }
    });
    

    Here is CSS

    .no-record #default_table{display:none;}
    

    and here is Official link.

提交回复
热议问题