簡體   English   中英

如何處理jquery數據表中的數據庫空值

[英]How to handle database null values in jquery datatable

我有一個 jquery 數據表,其中的數據來自數據庫,從 java servlet 中獲取。很少有列有空值。因此,我收到了類似的警告

DataTables 警告:table id=lplist - 為第 9 行請求未知參數“FeeCompany”。有關此錯誤的更多信息,請參閱http://datatables.net/tn/4

我希望這些空值被空字符串替換。有人可以指導如何實現這一點。

我的代碼片段如下

    <script
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script
    src="http://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>

<script
    src="http://cdn.datatables.net/scroller/1.2.2/js/dataTables.scroller.min.js"></script>
<link
    href="http://cdn.datatables.net/scroller/1.2.2/css/dataTables.scroller.css"
    rel="stylesheet" type="text/css" />

<link href="http://cdn.datatables.net/1.10.4/css/jquery.dataTables.css"
    rel="stylesheet" type="text/css" />
<title>Insert title here</title>
<script type="text/javascript">
            $(document).ready(function () {
                $("#lplist").dataTable({
                    "serverSide": true,
                    "sAjaxSource": "/JQueryDataTablesAll/CompanyGsonObjects",

                    dom: "rtiS",
                    scrollY: 450,
                    scrollX:true,
                    "processing": true,                     
                    "aoColumns": [
                                  { "mData": "InsuredName" },
                                  { "mData": "CustAddress_City" },
                                  { "mData": "CustAddress_State" },
                                  { "mData": "CustAddress_Zip" },
                                  { "mData": "CustSurvey_Location" },
                                  { "mData": "PolicyNo" },
                                  { "mData": "ProfitCenter" },
                                  { "mData": "FeeCompany" }, 

                              ]



                });
            });
        </script>
</head>
<body id="dt_example">
    <div id="container">
        <div id="links">
            Server-side processing with object source <br />
        </div>
        <div id="demo_jui">
            <table id="lplist" class="display">
                <thead>
                    <tr>
                        <th>Insured Name</th>
                        <th>City</th>
                        <th>State</th>
                        <th>Zip</th>
                        <th>Survey Location</th>
                        <th>PolicyNo</th>
                        <th>Profit Center</th>
                        <th>Fee Company</th>                        

                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>

    </div>

在初始化數據表時在選項中添加 defaultContent。 更多細節

列.默認內容

來自官方文檔的示例:

$('#example').dataTable( {
  "columns": [
    null,
    null,
    null,
    {
      "data": "first_name", // can be null or undefined
      "defaultContent": "<i>Not set</i>"
    }
  ]
} );

您可以使用mRender來指定出現空值時的顯示:

{ 
    "mData": "FeeCompany" 
    'mRender': function (data, type, full) {
        if (full[7] !== null) {
             return full[7]; 
         }else{
             return '';
         }
},
{

  "data": function(data, type, dataToSet) {

    return data.CourseEducator1 ? ? " " + "<br/>" + data.CourseEducator2 ? ? ";

  }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM