How to Solve Datatable field value is empty Error

When using datatable, the value returned by the background to the foreground will be empty. At this time, the foreground will report an error. Here are the prevention methods

$('#datatable1').DataTable( {
                ajax: {
                    "url": 'list',
                    "type": "POST",
                    data:{
                        title : function(){
                            return $("#title").val();
                        }
                    }
                },
                columnDefs: [{"defaultContent": "",
                              "targets": "_all"}],
                columns: [
                    { title: "序号", render:function(data,type,row,meta){
                        return meta.row + 1 + meta.settings._iDisplayStart }, width:"5%" },
                    { title: "推送类型", data:"mp_send_type", width:"5%" }, //x
                    { title: "推送标题", data:"mp_msg_title", width:"15%" },
                    { title: "任务ID(TASK id)", data:"mp_taskid", width:"12%" },//x */
                    { title: "推送时间", data:"mp_send_time", width:"7%" }, //x
                    { title: "推送人数", data:"mp_count", width:"5%" }, //x
                    { title: "操作人", data:"mp_admin_user_name", width:"7%" }, //    x
                    { title: "状态", render:function(data, type, row){
                        var str = "";
                        if(row.mp_status == "1"){
                            str = "<span class='label label-warning'>推送中</span>";
                        }else if(row.mp_status == "2"){
                            str = "<span class='label label-success'>推送完成</span>";
                        }else{
                            str = "<span class='label label-warning'>推送失败</span>";
                        }
                        return str;
                    } , width:"10%"}
                ]
                ,serverSide: true
                ,paging:true
                ,pagingType: "simple_numbers"
                ,lengthChange: true
                ,ordering:false
                ,info:false
                ,pageLength:10
                ,searching: false
                ,language: {
                    "url": "<%=contextPath %>/static/backend/js/Chinese.lang"
                }
            });

Intermediate:

columnDefs: [{"defaultContent": "",
                              "targets": "_all"}],

 

This means that no error will be reported when the default value is set to null

Similar Posts: