How to change the default infoEmpty mesagge dynamically
How to change the default infoEmpty mesagge dynamically
prox108
Posts: 27Questions: 12Answers: 0
Hi, I have created this table to show info:
let tb1= $('#tb1').DataTable({
'searching': false,
'paging': false,
'order': false,
'buttons': [],
//'serverSide': true,
//'async': true,
'processing': true,
"info":false,
ajax: {
complete: function (data) {
if (data['responseJSON']['desact'] !== undefined) {
}
},
url: 'a/b/ajax.get.php',
type: 'post',
dataType: 'json',
data: {id: v_id}
},
'columns': [
{data: 'est_descripcion', className: 'text-center', 'width': '25%', 'orderable': false}, // Establecimiento
{data: 'marcacion', className: 'text-center', 'width': '25%', 'orderable': false}, // Fecha
{data: 'fecha_hora', className: 'text-center', 'width': '25%', 'orderable': false}] // Hora
});
As you see I use the Complete propiety to validate if an object exists:
if (data['responseJSON']['desact'] !== undefined) {
}
Do you know how to change the default infoEmpty Message Dynamically?
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
Answers
The
language.infoEmpty
option is used to change the displayed message. What is it you want to change dynamically?Its unclear to me what you want to do with this code:
And how it would affect the infoEmpty message dynamically. Possibly
infoCallback
is what you want to use.Kevin
I want to show another message like:
Now:
To:
Because the data can conteins two possibilities:
You mean you want to replace the "Empty table" message with your own custom message, dynamically? You'd need to write it directly into the DOM on the
draw
event. There is no option in DataTables to dynamically update that message.Allan
Thanks!, I found out how.
complete: function (data) {
if (data['responseJSON']['desact'] !== undefined) {
$('#tb1 tbody tr td').html('desact');
}
}
If you are tying to change what is displayed under the table from
Showing 0 to 0 of 0 entries
to a message based on the json data then useinfo.callback
and inside useajax.json()
to get the json response, for example:Kevin