Using Firebase to list and sort records from greatest to least and print to HTML table body










0















I have a list of players and their accumulated winnings in firebase. Each record will be added to the from least to greatest.



<table id="toptenwinners" class="table table-hover table-sm">
<thead>
<tr>
<th>Rank</th>
<th>Player</th>
<th>Earnings</th>
<th>Tokens</th>
</tr>
</thead>
<tbody>
<tr> <-- start of insert
<th scope="row">1</th> <-- number generated after sort
<td>John Q Public</td> <-- from "player" in firebase
<td>552,133</td> <-- from "total earnings" in firebase
<td>1,212,808</td> <-- from "tokens" in firebase
</tr> <-- end of insert
..next record


The routine written doesn't seem to work well for this simple application.



dataRef.on('player',function(toptenwinners)

var toptenwinnersHTML = "";

toptenwinners.forEach(function(firebaseOrderReference)
var toptenwinners = dataRef.val();
console.log(toptenwinners);
var tableofwinners =

<tr>
<th scope="row">1</th>
<td>' + player + '</td>
<td>' + t_earnings + '</td>
<td>' + t_token + '</td>
</tr>;

toptenwinnersHTML = toptenwinnersHTML + tableofwinners;
);

$('#toptentable').html(toptenwinnersHTML);
);


I'm wondering if there is a simpler way (using jquery) to list all the 'players' in the DB, their earnings and tokens cleanly into the . Add a way to sort from highest tokens (t_tokens) to least, then number each "row" (i.e. 1, 2, 3, 4..) based on the sort.



Sample HTML Output:
Rank Name Earnings Tokens
1 Spongebob 55,222 1,234,555
2 DarthVadar 88,010 555,213
3 PacMan 12,123 120,111


enter image description here










share|improve this question




























    0















    I have a list of players and their accumulated winnings in firebase. Each record will be added to the from least to greatest.



    <table id="toptenwinners" class="table table-hover table-sm">
    <thead>
    <tr>
    <th>Rank</th>
    <th>Player</th>
    <th>Earnings</th>
    <th>Tokens</th>
    </tr>
    </thead>
    <tbody>
    <tr> <-- start of insert
    <th scope="row">1</th> <-- number generated after sort
    <td>John Q Public</td> <-- from "player" in firebase
    <td>552,133</td> <-- from "total earnings" in firebase
    <td>1,212,808</td> <-- from "tokens" in firebase
    </tr> <-- end of insert
    ..next record


    The routine written doesn't seem to work well for this simple application.



    dataRef.on('player',function(toptenwinners)

    var toptenwinnersHTML = "";

    toptenwinners.forEach(function(firebaseOrderReference)
    var toptenwinners = dataRef.val();
    console.log(toptenwinners);
    var tableofwinners =

    <tr>
    <th scope="row">1</th>
    <td>' + player + '</td>
    <td>' + t_earnings + '</td>
    <td>' + t_token + '</td>
    </tr>;

    toptenwinnersHTML = toptenwinnersHTML + tableofwinners;
    );

    $('#toptentable').html(toptenwinnersHTML);
    );


    I'm wondering if there is a simpler way (using jquery) to list all the 'players' in the DB, their earnings and tokens cleanly into the . Add a way to sort from highest tokens (t_tokens) to least, then number each "row" (i.e. 1, 2, 3, 4..) based on the sort.



    Sample HTML Output:
    Rank Name Earnings Tokens
    1 Spongebob 55,222 1,234,555
    2 DarthVadar 88,010 555,213
    3 PacMan 12,123 120,111


    enter image description here










    share|improve this question


























      0












      0








      0








      I have a list of players and their accumulated winnings in firebase. Each record will be added to the from least to greatest.



      <table id="toptenwinners" class="table table-hover table-sm">
      <thead>
      <tr>
      <th>Rank</th>
      <th>Player</th>
      <th>Earnings</th>
      <th>Tokens</th>
      </tr>
      </thead>
      <tbody>
      <tr> <-- start of insert
      <th scope="row">1</th> <-- number generated after sort
      <td>John Q Public</td> <-- from "player" in firebase
      <td>552,133</td> <-- from "total earnings" in firebase
      <td>1,212,808</td> <-- from "tokens" in firebase
      </tr> <-- end of insert
      ..next record


      The routine written doesn't seem to work well for this simple application.



      dataRef.on('player',function(toptenwinners)

      var toptenwinnersHTML = "";

      toptenwinners.forEach(function(firebaseOrderReference)
      var toptenwinners = dataRef.val();
      console.log(toptenwinners);
      var tableofwinners =

      <tr>
      <th scope="row">1</th>
      <td>' + player + '</td>
      <td>' + t_earnings + '</td>
      <td>' + t_token + '</td>
      </tr>;

      toptenwinnersHTML = toptenwinnersHTML + tableofwinners;
      );

      $('#toptentable').html(toptenwinnersHTML);
      );


      I'm wondering if there is a simpler way (using jquery) to list all the 'players' in the DB, their earnings and tokens cleanly into the . Add a way to sort from highest tokens (t_tokens) to least, then number each "row" (i.e. 1, 2, 3, 4..) based on the sort.



      Sample HTML Output:
      Rank Name Earnings Tokens
      1 Spongebob 55,222 1,234,555
      2 DarthVadar 88,010 555,213
      3 PacMan 12,123 120,111


      enter image description here










      share|improve this question
















      I have a list of players and their accumulated winnings in firebase. Each record will be added to the from least to greatest.



      <table id="toptenwinners" class="table table-hover table-sm">
      <thead>
      <tr>
      <th>Rank</th>
      <th>Player</th>
      <th>Earnings</th>
      <th>Tokens</th>
      </tr>
      </thead>
      <tbody>
      <tr> <-- start of insert
      <th scope="row">1</th> <-- number generated after sort
      <td>John Q Public</td> <-- from "player" in firebase
      <td>552,133</td> <-- from "total earnings" in firebase
      <td>1,212,808</td> <-- from "tokens" in firebase
      </tr> <-- end of insert
      ..next record


      The routine written doesn't seem to work well for this simple application.



      dataRef.on('player',function(toptenwinners)

      var toptenwinnersHTML = "";

      toptenwinners.forEach(function(firebaseOrderReference)
      var toptenwinners = dataRef.val();
      console.log(toptenwinners);
      var tableofwinners =

      <tr>
      <th scope="row">1</th>
      <td>' + player + '</td>
      <td>' + t_earnings + '</td>
      <td>' + t_token + '</td>
      </tr>;

      toptenwinnersHTML = toptenwinnersHTML + tableofwinners;
      );

      $('#toptentable').html(toptenwinnersHTML);
      );


      I'm wondering if there is a simpler way (using jquery) to list all the 'players' in the DB, their earnings and tokens cleanly into the . Add a way to sort from highest tokens (t_tokens) to least, then number each "row" (i.e. 1, 2, 3, 4..) based on the sort.



      Sample HTML Output:
      Rank Name Earnings Tokens
      1 Spongebob 55,222 1,234,555
      2 DarthVadar 88,010 555,213
      3 PacMan 12,123 120,111


      enter image description here







      javascript jquery firebase firebase-realtime-database






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 3:52









      Frank van Puffelen

      239k29382408




      239k29382408










      asked Nov 15 '18 at 1:22









      NanoNetNanoNet

      496




      496






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Sad how questions go stale around here. Anywho, figured it out. The trick was in using the data.ref().once function to list all the content of the DB then gracefully pass the results (on each iteration) to the html table format.



          Worked like a charm..



          function listthechamps() 

          let y = 0
          $("#tableChampion").empty();

          var database = firebase.database();
          database.ref().once('value', function (snapshot)
          if (snapshot.exists())
          var content = '';
          snapshot.forEach(function (data)
          y++
          var val = data.val();
          content += '<tr>';
          content += '<td>' + y + '</td>';
          content += '<td>' + val.player + '</td>';
          content += '<td>' + val.t_earnings + '</td>';
          content += '<td>' + val.t_token + '</td>';
          content += '</tr>';
          );
          $('#tableChampion').append(content);

          );






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311133%2fusing-firebase-to-list-and-sort-records-from-greatest-to-least-and-print-to-html%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Sad how questions go stale around here. Anywho, figured it out. The trick was in using the data.ref().once function to list all the content of the DB then gracefully pass the results (on each iteration) to the html table format.



            Worked like a charm..



            function listthechamps() 

            let y = 0
            $("#tableChampion").empty();

            var database = firebase.database();
            database.ref().once('value', function (snapshot)
            if (snapshot.exists())
            var content = '';
            snapshot.forEach(function (data)
            y++
            var val = data.val();
            content += '<tr>';
            content += '<td>' + y + '</td>';
            content += '<td>' + val.player + '</td>';
            content += '<td>' + val.t_earnings + '</td>';
            content += '<td>' + val.t_token + '</td>';
            content += '</tr>';
            );
            $('#tableChampion').append(content);

            );






            share|improve this answer



























              0














              Sad how questions go stale around here. Anywho, figured it out. The trick was in using the data.ref().once function to list all the content of the DB then gracefully pass the results (on each iteration) to the html table format.



              Worked like a charm..



              function listthechamps() 

              let y = 0
              $("#tableChampion").empty();

              var database = firebase.database();
              database.ref().once('value', function (snapshot)
              if (snapshot.exists())
              var content = '';
              snapshot.forEach(function (data)
              y++
              var val = data.val();
              content += '<tr>';
              content += '<td>' + y + '</td>';
              content += '<td>' + val.player + '</td>';
              content += '<td>' + val.t_earnings + '</td>';
              content += '<td>' + val.t_token + '</td>';
              content += '</tr>';
              );
              $('#tableChampion').append(content);

              );






              share|improve this answer

























                0












                0








                0







                Sad how questions go stale around here. Anywho, figured it out. The trick was in using the data.ref().once function to list all the content of the DB then gracefully pass the results (on each iteration) to the html table format.



                Worked like a charm..



                function listthechamps() 

                let y = 0
                $("#tableChampion").empty();

                var database = firebase.database();
                database.ref().once('value', function (snapshot)
                if (snapshot.exists())
                var content = '';
                snapshot.forEach(function (data)
                y++
                var val = data.val();
                content += '<tr>';
                content += '<td>' + y + '</td>';
                content += '<td>' + val.player + '</td>';
                content += '<td>' + val.t_earnings + '</td>';
                content += '<td>' + val.t_token + '</td>';
                content += '</tr>';
                );
                $('#tableChampion').append(content);

                );






                share|improve this answer













                Sad how questions go stale around here. Anywho, figured it out. The trick was in using the data.ref().once function to list all the content of the DB then gracefully pass the results (on each iteration) to the html table format.



                Worked like a charm..



                function listthechamps() 

                let y = 0
                $("#tableChampion").empty();

                var database = firebase.database();
                database.ref().once('value', function (snapshot)
                if (snapshot.exists())
                var content = '';
                snapshot.forEach(function (data)
                y++
                var val = data.val();
                content += '<tr>';
                content += '<td>' + y + '</td>';
                content += '<td>' + val.player + '</td>';
                content += '<td>' + val.t_earnings + '</td>';
                content += '<td>' + val.t_token + '</td>';
                content += '</tr>';
                );
                $('#tableChampion').append(content);

                );







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '18 at 4:10









                NanoNetNanoNet

                496




                496





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311133%2fusing-firebase-to-list-and-sort-records-from-greatest-to-least-and-print-to-html%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                    Museum of Modern and Contemporary Art of Trento and Rovereto