zoukankan      html  css  js  c++  java
  • DataTable 字段值为空的时候报错的解决

    在使用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"}],

    这一点就是设置默认值为空的时候,不报错

  • 相关阅读:
    [Android学习笔记]Activity
    [Android学习笔记]Activity,View,Windows简介
    [Android]Eclipse的使用
    [Cocos2d-x]解决Android平台ndk-build时不自动删除外部库
    [Cocos2d-x]Android的android.mk文件通用版本
    [C++][STL]string记录
    nyoj-103-A+B Problem II
    nyoj-95-众数问题
    nyoj-187-快速查找素数
    nyoj-8-一种排序
  • 原文地址:https://www.cnblogs.com/sunxun/p/9171683.html
Copyright © 2011-2022 走看看