2016-11-08 52 views
0

嗨,我已經使用下面的代碼創建了jQuery的數據表..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", 
       }); 
+0

'可爲空'或列本身不會存在? –

+0

不存在列。只有值爲空 – boycod3

回答

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 
}, ], 

其良好的,如果你確信任何column的可能出現空分配defaultContent選項,所有列。

+0

沒有變化仍然是相同的錯誤 – boycod3

+0

你可以請嘗試複製它在這裏與樣本數據? –

+0

你的意思是來自服務器的迴應? – boycod3