I want to define default value for all empty cells in all datatables i have, but i don't want to do this for every column like that:
$('#example').dataTable( {
"ajaxSource": "sources/deep.txt",
"columns": [
{ "data": "engine"
"render": function (data, type, row) {
if(row.platform == null) {
return "-";
} else {
return row.platform.display;
}
},
},
{ "data": "browser",
"render": function (data, type, row) {
if(row.platform == null) {
return "-";
} else {
return row.platform.display;
}
},
},
{
"data": "platform",
"render": function (data, type, row) {
if(row.platform == null) {
return "-";
} else {
return row.platform.display;
}
},
}
]
} );
Is there a chance to define this in datatable defaults? How should i do that? Or there is a better place to define this render default action for empty cells?
/* default values for tables */
$.extend(true, $.fn.dataTable.defaults, {
dom: "<'table_scroll_container't>" + "<'dt-row dt-bottom-row'<'col-md-4 m-b-10 h30 no-margin-md text-center text-md-left'B i><'col-md-8 m-b-10 h30 no-margin-md text-center text-md-right'l<'clearfix visible-xs-block visible-sm-block'>p>>",
buttons: [],
stateSave: true,
stateDuration: -1,
iDisplayLength: 50,
autoWidth: false,
processing: true,
language: {
"processing": "Processing...",
"info": "Showing _TOTAL_ entries",
"infoEmpty": "No records available",
"infoFiltered": "filtered from _MAX_"
}
});
All other tips are welcome :)
Use columns.defaultContent
to set default content for a column.
You can also use it to set default values for all tables. For example:
$.extend(true, $.fn.dataTable.defaults, {
columnDefs: [
{
targets: '_all',
defaultContent: '-'
}
]
});
See this example for code and demonstration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With