在使用Datatable的时候,后台返回给前台的值会有空的时候,而这个时候,前台会报错,这里讲防治方法;
$('#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'>推送中"; }else if(row.mp_status == "2"){ str = "<span class='label label-success'>推送完成"; }else{ str = "<span class='label label-warning'>推送失败"; } 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" } });
中间的:
columnDefs: [{"defaultContent": "", "targets": "_all"}],
这一点就是设置默认值为空的时候,不报错
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/7958.html