I trying to connect the datatable to firebase but i cant figure it out

I trying to connect the datatable to firebase but i cant figure it out

NikozyNikozy Posts: 6Questions: 3Answers: 0
edited March 2021 in Free community support

My html code

<!DOCTYPE html>

<head>
    <title>Datatables</title>
</head>
<html>

<body>
    <table id="user_data" class="display" width="100%" cellspacing="0">
        <thead>
            <tr>
                <th>Nama</th>
                <th>Email</th>
                <th>No.Hp</th>
                <th>Status</th>
            </tr>
        </thead>

        <tbody id="table-body-pengguna">

        </tbody>
    </table>
</body>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.3.0/firebase-storage.js"></script>


<script src="dt2.js"></script>

</html>  

My JS code

var firebaseConfig = {
    apiKey: "AIzaSyAdWq4-ZE4Yv87w_AEyy5b5JwkW9A8iL3U",
    authDomain: "contact-form-38b0b.firebaseapp.com",
    databaseURL: "https://contact-form-38b0b-default-rtdb.firebaseio.com",
    projectId: "contact-form-38b0b",
    storageBucket: "contact-form-38b0b.appspot.com",
    messagingSenderId: "748179068137",
    appId: "1:748179068137:web:2a3ad3ed4d8a07ac990c78",
    measurementId: "G-HC8E0ED0TD"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();

var rootRef = firebase.database().ref().child("AdminID");

rootRef.on("child_added", snap => {
    var AdminID = snap.child("AdminID").val();
    var AdminName = snap.child("AdminName").val();
    var AdminPassword = snap.child("AdminPassword").val();
    var AdminPhone = snap.child("AdminPhone").val();

    $("#table-body-pengguna").append("<tr><td>" + AdminID + "</td><td>" + AdminName +
        "</td><td>" + AdminPassword + "</td><td>" + AdminPhone + "</td></tr>");
})

Edited by Colin - 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

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

    Is this a DataTables issue? It sounds like this question would be best asked on StackOverflow unless I'm missing something!

    Colin

  • NikozyNikozy Posts: 6Questions: 3Answers: 0

    I am beginner in data table can you provide me some code which can connect the data table to firebase

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Please refer to Colin's reply.
    There is no mention of DataTables in your code.

This discussion has been closed.