我有一个jQuery数据表,数据来自数据库,从java servlet获取。很少有列为空值。
我希望将这些空值替换为空字符串。有人可以指导如何实现此目的。
我的代码段如下
<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。更多细节
columns.defaultContent
官方文档中的示例:
$('#example').dataTable( {
"columns": [
null,
null,
null,
{
"data": "first_name", // can be null or undefined
"defaultContent": "<i>Not set</i>"
}
]
} );
关于javascript - 如何处理jQuery数据表中的数据库空值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27502267/