how can initializing datatable after take my data in FIREBASE?

how can initializing datatable after take my data in FIREBASE?

LuyzLuyz Posts: 2Questions: 1Answers: 0

I have a problem when I take my data from FireBase and tried to display this data in the data table, because datatable Initializes before

My code is this:

$(document).ready(function(){

firebase.database().ref('Usuarios').on('child_added',function(snapshot) {
    var dataSet = [[snapshot.key, snapshot.val().Nombre];

});

$('#myTable').DataTable({
    "bFilter": false,
    data: dataSet
});

});

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Answer ✓

    You would need to either:

    1. initialise the DataTable in the callback once the data has been loaded
    2. Use rows.add() to add the rows.

    Allan

  • LuyzLuyz Posts: 2Questions: 1Answers: 0
    edited January 2017

    Thank Allan, It's done

    var table = $('#myTable').DataTable ( {
    "bFilter": false
    } );

    firebase.database().ref('Usuarios').on('child_added',function(snapshot) {
    var dataSet = [snapshot.key, snapshot.val().Nombre];
    table.rows.add([dataSet]).draw();
    });

This discussion has been closed.