How to change the default infoEmpty mesagge dynamically

How to change the default infoEmpty mesagge dynamically

prox108prox108 Posts: 27Questions: 12Answers: 0
edited September 12 in Free community support

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

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,949

    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:

                complete: function (data) {
                    if (data['responseJSON']['desact'] !== undefined) {
                    }
                },
    

    And how it would affect the infoEmpty message dynamically. Possibly infoCallback is what you want to use.

    Kevin

  • prox108prox108 Posts: 27Questions: 12Answers: 0
    edited September 12

    I want to show another message like:

    Now:

    To:

    Because the data can conteins two possibilities:

    1. Data
    2. Empty Data
    3. Empty Data and desact object
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Answer ✓

    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

  • prox108prox108 Posts: 27Questions: 12Answers: 0

    Thanks!, I found out how.

    complete: function (data) { if (data['responseJSON']['desact'] !== undefined) { $('#tb1 tbody tr td').html('desact'); } }

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,949

    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 use info.callback and inside use ajax.json() to get the json response, for example:

    var json = this.api().ajax.json();
    

    Kevin

Sign In or Register to comment.