How do I fill the info field with server information

How do I fill the info field with server information

Fl0x23Fl0x23 Posts: 4Questions: 1Answers: 0
edited November 2018 in Free community support

Hello people,

I would like to enter an information in the same position as "table_info". The entry should contain the server time. Since the server time unfortunately can not be queried by Javascript, I had the idea to jquery them via PHP script. My problem now is that I do not get the info in the field. It is certainly because it is asyncron but how can i solve it?

Here is a detail:

$.getJSON('./update.php', function(data) {
    console.log(data); <- I need this information in the info field.
});                                                     |
                                                        |
                                                        |
$(document).ready(function () {                         |
    var table = $('#table').DataTable({                 |
        "infoCallback": function (response) {           |
            <- here ------------------------------------+
        }
    });
});

Many thanks in advance.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @Fl0x23 ,

    Can't you just store that time data in a variable and access it later in the infoCallback?

    Cheers,

    Colin

  • Fl0x23Fl0x23 Posts: 4Questions: 1Answers: 0

    @colin

    Thank you for you answer, but how should that work? The reponse of php file comes later.

    Regrads

    Fl0x23

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Ah, I see. The infoCallback is called every draw, line 2, you could set the variable to "data", then force a table draw with draw() - passing in "page" will keep the paging, ordering and searching the same.

    C

  • Fl0x23Fl0x23 Posts: 4Questions: 1Answers: 0

    Do you have a example please?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited November 2018
    var infoData = "No data yet";
    $.getJSON('./update.php', function(data) {
        infoData = data;
    });                                                     
                                                            
                                                            
    $(document).ready(function () {                         
        var table = $('#table').DataTable({                 
            "infoCallback": function (response) {           
                return infoData;
            }
        });
    });
    
  • Fl0x23Fl0x23 Posts: 4Questions: 1Answers: 0
    edited November 2018

    It works thank you very much.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Ah, sorry, I forgot the draw() :

    var infoData = "No data yet";
    $.getJSON('./update.php', function(data) {
        infoData = data;
        table.draw('page');
    });                                                     
                                                            
                                                            
    $(document).ready(function () {                         
        var table = $('#table').DataTable({                 
            "infoCallback": function (response) {           
                return infoData;
            }
        });
    });
    
This discussion has been closed.