首页 > 解决方案 > 如何在数据表中显示自定义消息?

问题描述

我有数据表,我需要在没有数据时显示自定义错误消息。如果成功消息添加的记录不绑定。当数据表“zeroRecords”:“”时,应显示自定义消息,不影响实际功能

table = $('#operator-datatable').DataTable({
        processing: true,
        serverSide: true,
        searching: false,
        stateSave: boolstatus,
        ajax: {
            url: _API.apiBaseUrl + 'OperatorManage/Operator/List',
            type: 'POST',
            headers: _API.headers,
            "dataSrc":"tableData",
            data: function (d) {
                d.columns[0].search.value = $('#bankernumber').val();
                d.columns[6].search.value = $('#branchnumber').val();
                d.columns[4].search.value = $('#revokestatus').val();
                d.columns[2].search.value = $('#operatorjurisdictiontype').val();
            },
            success: function (res) {
                $('.dataTables_processing').hide();
                //var response = JSON.parse(res);
                console.log(res);
                alert("hi");
            },
            error: function (xhr, textStatus, errorThrown) {
                _API.alertAjaxError(xhr);
                $('.dataTables_processing').hide();
            },
        },
        columns: [
            { data: 'bankernumber' },
            { data: 'bankername' },
            { data: 'jurisdictiontype' },

标签: jquerydatatable

解决方案


Taken from the DataTable docs, add this code:

table = $("#operator-datatable").DataTable({
    "language": {
        "zeroRecords": "Custom error message goes here"
    }
    //Rest of your code
})

推荐阅读