在使用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 }, "5%" }, { title: "推送类型", data:"mp_send_type", "5%" }, //x { title: "推送标题", data:"mp_msg_title", "15%" }, { title: "任务ID(TASK id)", data:"mp_taskid", "12%" },//x */ { title: "推送时间", data:"mp_send_time", "7%" }, //x { title: "推送人数", data:"mp_count", "5%" }, //x { title: "操作人", data:"mp_admin_user_name", "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; } , "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"}],
这一点就是设置默认值为空的时候,不报错