Jquery Datatable null列

时间:2016-11-08 09:30:01

标签: jquery datatables

您好我使用下面的代码创建了jquery数据表..

列电子邮件ID和激活日期可以为空。当我呈现表格时,它显示来自第0行的数据源的“请求未知参数”电子邮件

 var tblAllKeys = $('#tblAllKeys').dataTable({
                    "bDestroy" : true,
                    "bProcessing" : true,
                    "bServerSide" : true,
                    "bLenthChange" : false,
                    "iDisplayLength" : 10,
                    "sAjaxSource" : "loadAllKeys",
                    "oLanguage" : {
                        "sSearch" : "Search By Activation Key:"
                    },
                    "aoColumns" : [
                     {"sTitle" : "No.","mData" : null,"aTargets": [ 0 ],
                        "fnRender" : function(obj) {
                            var columnIndex = obj.oSettings._iDisplayStart + obj.iDataRow+1
                            return columnIndex;
                        }
                    },
                    {"sTitle" : "Activation Key","mData" : "key", "bSearchable" : true},
                    {"sTitle" : "Email ID","mData" :  "email" , "bSearchable" : false},
                    {"sTitle" : "App Edition","mData" : "edition", "bSearchable" : false},
                    {"sTitle" : "Batch Code","mData" : "batch", "bSearchable" : false},
                    {"sTitle" : "Activated Date","mData" : "aDate" , "bSearchable" : false},
                    {"sTitle" : "Generated Date","mData" : "gDate", "bSearchable" : false},
                    {"sTitle" : "Status","mData" : "status", "bSearchable" : false},
                    ],
                       "fnServerData" : function(sSource, aoData, fnCallback) {
                        $.ajax({
                         "dataType" : 'json',
                         "type" : "GET",
                         "url" : sSource,
                         "data" : aoData,
                         "success" : fnCallback
                        });
                       },
                       "sPaginationType" : "full_numbers",
                });

1 个答案:

答案 0 :(得分:1)

您可以根据 columns.defaultContent 使用 docs on this error 选项,以便在列不显示时显示默认值或空字符串有任何价值。

"aoColumns": [{
  "sTitle": "No.",
  "mData": null,
  "aTargets": [0],
  "fnRender": function(obj) {
    var columnIndex = obj.oSettings._iDisplayStart + obj.iDataRow + 1
    return columnIndex;
  }
}, {
  "sTitle": "Activation Key",
  "mData": "key",
  "bSearchable": true
}, {
  "sTitle": "Email ID",
  "defaultContent":"",//or specify any other value
  "mData": "email",
  "bSearchable": false
}, {
  "sTitle": "App Edition",
  "mData": "edition",
  "bSearchable": false
}, {
  "sTitle": "Batch Code",
  "mData": "batch",
  "bSearchable": false
}, {
  "sTitle": "Activated Date",
  "mData": "aDate",
  "bSearchable": false
}, {
  "sTitle": "Generated Date",
  "mData": "gDate",
  "bSearchable": false
}, {
  "sTitle": "Status",
  "mData": "status",
  "bSearchable": false
}, ],

如果您确定defaultContent中的任何一个可能为空,则可以为所有列分配column选项。