Datatables表格数据初始化时回调函数中修改要显示的值
场景
Datables初始化表数据后,返回的status状态值为1,2,3
现在要根据返回值的状态显示相应的中文。
实现
{ data: 'status',
render: function (data, type, full, meta ) {
if(data.trim()=="1"){
return '未提交'
}else if(data.trim()=="2"){
return '已提交'
}else if(data.trim()=="3"){
return '已打印'
}else{
return '未知状态'
}
} },
举例:
function dataTableInit(){
return $('#wmsReceiveOrder_table_id').DataTable({
"language": {
"processing": "处理中...",
"lengthMenu": "显示 _MENU_ 项结果",
"zeroRecords": "没有匹配结果",
"info": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
"infoEmpty": "显示第 0 至 0 项结果,共 0 项",
"infoFiltered": "(由 _MAX_ 项结果过滤)",
"infoPostFix": "",
"search": "搜索:",
"searchPlaceholder": "搜索...",
"url": "",
"emptyTable": "表中数据为空",
"loadingRecords": "载入中...",
"infoThousands": ",",
"paginate": {
"first": "首页",
"previous": "上页",
"next": "下页",
"last": "末页"
},
"aria": {
paginate: {
first: '首页',
previous: '上页',
next: '下页',
last: '末页'
},
"sortAscending": ": 以升序排列此列",
"sortDescending": ": 以降序排列此列"
},
"decimal": "-",
"thousands": "."
},
"processing": true,
"searching" : false,
"serverSide": true,
"stateSave": true,
"pageLength": 5,
"lengthMenu": [ 5,10, 25, 50, 75, 100 ],
"dom": '<"top">rt<"bottom"flpi><"clear">',
"columnDefs": [ {
"searchable": false,
"orderable": false,
"targets": 0
}],
columns: [
{ data: 'id' },
{ data: 'purchaseCode' },
{ data: 'deliveryTime',
render: function (data, type, full, meta ) {
return moment(data).format("YYYY-MM-DD HH:mm:ss");
} },
{ data: 'createrName' },
{ data: 'deliveryCode' },
{ data: 'gmtCreat',
render: function (data, type, full, meta ) {
return moment(data).format("YYYY-MM-DD HH:mm:ss");
} },
{ data: 'createrName' },
{ data: 'status',
render: function (data, type, full, meta ) {
if(data.trim()=="1"){
return '未提交'
}else if(data.trim()=="2"){
return '已提交'
}else if(data.trim()=="3"){
return '已打印'
}else{
return '未知状态'
}
} },
],
"ajax": function (data, callback, setting) {
$.each(data.columns,function (index,value) {
//匹配所有input
$("#searchCondition").find('input[type="text"]').each(function () {
if(value.data === $(this).attr('id')){
value.search.value = $(this).val();
}
});
//匹配所有select
debugger
$("#searchCondition select").each(function () {
debugger
if(value.data === $(this).attr('id')){
value.search.value = $(this).val();
}
});
})
$.ajax({
type: 'POST',
url: "/wmsReceiveOrder/doPageForReceiveOrderTable",
cache: false, //禁用缓存
data: JSON.stringify(data), //传入组装的参数
contentType: "application/json",
dataType: "json",
success: function (result) {
debugger
callback(result);
}
})
}
})
}