我想显示具有空列的行。我试图使用“defaultContent”:''但它不起作用。
这是我的数据表代码:
var table = $('#tablaCliente').DataTable({
"columnDefs": [{
"width": "5%",
"targets": [0]
},
{
"className": "text-center custom-middle-align",
"targets": [2, 3, 4, 5, 6]
}, ],
"language":
{
"processing": "<div class='overlay custom-loader-background'><i class='fa fa-cog fa-spin custom-loader-color'></i></div>"
},
"processing": true,
"serverSide": true,
"ajax":
{
"url": "/Mantenimiento/FiltrarClientesTablaAsync",
"type": "POST",
"dataType": "JSON",
},
"columns": [
{
"data": "Name"
},
{
"data": "LatName"
},
{
"data": "RucClient", //This could be null
"defaultContent": ""
},
{
"data": "Phone"
},
{
"data": "Email", //This could be null
"defaultContent": ""
}
],
});
还有其他可以帮助我的解决方案吗?
答案 0 :(得分:0)
您可以使用渲染来处理数据。 https://datatables.net/reference/option/columns.render
"columns": [
{
"data": "Name",
"render": function (data, type, full, meta) {
if (!data) {
return '';
}
}
},
答案 1 :(得分:0)
为了避免重复编程,我编写了一个名为processNull的函数。在它内部,它将检查null是否无效,如果是,它将返回空,如果不是,则它将呈现整行。
function processNull(data) {
if (!data) {
return '';
} else {
return data;
}
}
var table = $('#tablaCliente').DataTable({
"columnDefs": [{
"width": "5%",
"targets": [0]
},
{
"className": "text-center custom-middle-align",
"targets": [2, 3, 4, 5, 6]
}, ],
"language":
{
"processing": "<div class='overlay custom-loader-background'><i class='fa fa-cog fa-spin custom-loader-color'></i></div>"
},
"processing": true,
"serverSide": true,
"ajax":
{
"url": "/Mantenimiento/FiltrarClientesTablaAsync",
"type": "POST",
"dataType": "JSON",
},
"columns": [
{
"data": "Name"
},
{
"data": "LatName"
},
{
"data": "RucClient", //This could be null
"defaultContent": "",
"render": processNull
},
{
"data": "Phone"
},
{
"data": "Email", //This could be null
"defaultContent": ""
"render": processNull
}
],
});