Load table via list ajax












0















I'm trying to load a table via post ajax, but it's not loading properly.



table:



<table class="table table-responsive table-hover table-striped" id="tableestoque" style="font-size:12px;">
<thead>
<tr>
<th>Nome Empresa</th>
<th>Qtd</th>
</tr>
</thead>
<tbody></tbody>
</table>


And here is how I am loading:



$.each(data.listaEstoque, function (i, item) {
$("#tableestoque").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});


enter image description here



It is loading like this, I want you to load each one into a column, and if you have more rows, each in a row.










share|improve this question


















  • 1





    $("#tableestoque").append("<tr" => $("#tableestoque tbody").append("<tr>". You are missing the tbody element and the closing of the <tr>.

    – Dekel
    Nov 19 '18 at 13:20













  • just a typo - you missed the > from your <tr, should be <tr>

    – ADyson
    Nov 19 '18 at 13:20






  • 1





    I think you need append you html to <tbody>, not to <table>

    – Oleg Nurutdinov
    Nov 19 '18 at 13:20











  • Not sure what you mean by "clean only the tr".

    – Dekel
    Nov 19 '18 at 13:23











  • @Deker I need to clear the included data, not the header

    – marianac_costa
    Nov 19 '18 at 13:25
















0















I'm trying to load a table via post ajax, but it's not loading properly.



table:



<table class="table table-responsive table-hover table-striped" id="tableestoque" style="font-size:12px;">
<thead>
<tr>
<th>Nome Empresa</th>
<th>Qtd</th>
</tr>
</thead>
<tbody></tbody>
</table>


And here is how I am loading:



$.each(data.listaEstoque, function (i, item) {
$("#tableestoque").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});


enter image description here



It is loading like this, I want you to load each one into a column, and if you have more rows, each in a row.










share|improve this question


















  • 1





    $("#tableestoque").append("<tr" => $("#tableestoque tbody").append("<tr>". You are missing the tbody element and the closing of the <tr>.

    – Dekel
    Nov 19 '18 at 13:20













  • just a typo - you missed the > from your <tr, should be <tr>

    – ADyson
    Nov 19 '18 at 13:20






  • 1





    I think you need append you html to <tbody>, not to <table>

    – Oleg Nurutdinov
    Nov 19 '18 at 13:20











  • Not sure what you mean by "clean only the tr".

    – Dekel
    Nov 19 '18 at 13:23











  • @Deker I need to clear the included data, not the header

    – marianac_costa
    Nov 19 '18 at 13:25














0












0








0








I'm trying to load a table via post ajax, but it's not loading properly.



table:



<table class="table table-responsive table-hover table-striped" id="tableestoque" style="font-size:12px;">
<thead>
<tr>
<th>Nome Empresa</th>
<th>Qtd</th>
</tr>
</thead>
<tbody></tbody>
</table>


And here is how I am loading:



$.each(data.listaEstoque, function (i, item) {
$("#tableestoque").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});


enter image description here



It is loading like this, I want you to load each one into a column, and if you have more rows, each in a row.










share|improve this question














I'm trying to load a table via post ajax, but it's not loading properly.



table:



<table class="table table-responsive table-hover table-striped" id="tableestoque" style="font-size:12px;">
<thead>
<tr>
<th>Nome Empresa</th>
<th>Qtd</th>
</tr>
</thead>
<tbody></tbody>
</table>


And here is how I am loading:



$.each(data.listaEstoque, function (i, item) {
$("#tableestoque").append("<tr"
+ "<td>" + item.empresaProduto.nome + "</td>"
+ "<td>" + item.qtd + "</td>"
+ "</tr>")
});


enter image description here



It is loading like this, I want you to load each one into a column, and if you have more rows, each in a row.







javascript jquery ajax






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 13:18









marianac_costamarianac_costa

1358




1358








  • 1





    $("#tableestoque").append("<tr" => $("#tableestoque tbody").append("<tr>". You are missing the tbody element and the closing of the <tr>.

    – Dekel
    Nov 19 '18 at 13:20













  • just a typo - you missed the > from your <tr, should be <tr>

    – ADyson
    Nov 19 '18 at 13:20






  • 1





    I think you need append you html to <tbody>, not to <table>

    – Oleg Nurutdinov
    Nov 19 '18 at 13:20











  • Not sure what you mean by "clean only the tr".

    – Dekel
    Nov 19 '18 at 13:23











  • @Deker I need to clear the included data, not the header

    – marianac_costa
    Nov 19 '18 at 13:25














  • 1





    $("#tableestoque").append("<tr" => $("#tableestoque tbody").append("<tr>". You are missing the tbody element and the closing of the <tr>.

    – Dekel
    Nov 19 '18 at 13:20













  • just a typo - you missed the > from your <tr, should be <tr>

    – ADyson
    Nov 19 '18 at 13:20






  • 1





    I think you need append you html to <tbody>, not to <table>

    – Oleg Nurutdinov
    Nov 19 '18 at 13:20











  • Not sure what you mean by "clean only the tr".

    – Dekel
    Nov 19 '18 at 13:23











  • @Deker I need to clear the included data, not the header

    – marianac_costa
    Nov 19 '18 at 13:25








1




1





$("#tableestoque").append("<tr" => $("#tableestoque tbody").append("<tr>". You are missing the tbody element and the closing of the <tr>.

– Dekel
Nov 19 '18 at 13:20







$("#tableestoque").append("<tr" => $("#tableestoque tbody").append("<tr>". You are missing the tbody element and the closing of the <tr>.

– Dekel
Nov 19 '18 at 13:20















just a typo - you missed the > from your <tr, should be <tr>

– ADyson
Nov 19 '18 at 13:20





just a typo - you missed the > from your <tr, should be <tr>

– ADyson
Nov 19 '18 at 13:20




1




1





I think you need append you html to <tbody>, not to <table>

– Oleg Nurutdinov
Nov 19 '18 at 13:20





I think you need append you html to <tbody>, not to <table>

– Oleg Nurutdinov
Nov 19 '18 at 13:20













Not sure what you mean by "clean only the tr".

– Dekel
Nov 19 '18 at 13:23





Not sure what you mean by "clean only the tr".

– Dekel
Nov 19 '18 at 13:23













@Deker I need to clear the included data, not the header

– marianac_costa
Nov 19 '18 at 13:25





@Deker I need to clear the included data, not the header

– marianac_costa
Nov 19 '18 at 13:25












2 Answers
2






active

oldest

votes


















0














I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.



var data = [{
id: 1,
name: 'Name1'
}, {
id: 2,
name: 'Name2'
}];
var $table = $("#tableestoque");
var $tr, $td1, $td2;

data.forEach(function(item) {
$tr = $('<tr>');
$td1 = $('<td>' + item.id + '</td>');
$td2 = $('<td>' + item.name + '</td>');
$tr.append($td1).append($td2);
$table.append($tr);
});





share|improve this answer































    -1














    It looks like you need to append your html to <tbody> like this:



    $.each(data.listaEstoque, function (i, item) {
    $("#tableestoque tbody").append("<tr"
    + "<td>" + item.empresaProduto.nome + "</td>"
    + "<td>" + item.qtd + "</td>"
    + "</tr>")
    });





    share|improve this answer
























    • Did you even read the comments before answering ?

      – Dekel
      Nov 19 '18 at 13:23











    • @Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)

      – Oleg Nurutdinov
      Nov 19 '18 at 13:31











    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%2f53375500%2fload-table-via-list-ajax%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.



    var data = [{
    id: 1,
    name: 'Name1'
    }, {
    id: 2,
    name: 'Name2'
    }];
    var $table = $("#tableestoque");
    var $tr, $td1, $td2;

    data.forEach(function(item) {
    $tr = $('<tr>');
    $td1 = $('<td>' + item.id + '</td>');
    $td2 = $('<td>' + item.name + '</td>');
    $tr.append($td1).append($td2);
    $table.append($tr);
    });





    share|improve this answer




























      0














      I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.



      var data = [{
      id: 1,
      name: 'Name1'
      }, {
      id: 2,
      name: 'Name2'
      }];
      var $table = $("#tableestoque");
      var $tr, $td1, $td2;

      data.forEach(function(item) {
      $tr = $('<tr>');
      $td1 = $('<td>' + item.id + '</td>');
      $td2 = $('<td>' + item.name + '</td>');
      $tr.append($td1).append($td2);
      $table.append($tr);
      });





      share|improve this answer


























        0












        0








        0







        I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.



        var data = [{
        id: 1,
        name: 'Name1'
        }, {
        id: 2,
        name: 'Name2'
        }];
        var $table = $("#tableestoque");
        var $tr, $td1, $td2;

        data.forEach(function(item) {
        $tr = $('<tr>');
        $td1 = $('<td>' + item.id + '</td>');
        $td2 = $('<td>' + item.name + '</td>');
        $tr.append($td1).append($td2);
        $table.append($tr);
        });





        share|improve this answer













        I created sample fiddle for you. Right now you are iterating over each element, not over each object. You should iterate over object using forEach statement.



        var data = [{
        id: 1,
        name: 'Name1'
        }, {
        id: 2,
        name: 'Name2'
        }];
        var $table = $("#tableestoque");
        var $tr, $td1, $td2;

        data.forEach(function(item) {
        $tr = $('<tr>');
        $td1 = $('<td>' + item.id + '</td>');
        $td2 = $('<td>' + item.name + '</td>');
        $tr.append($td1).append($td2);
        $table.append($tr);
        });






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 13:28









        dganencodganenco

        2217




        2217

























            -1














            It looks like you need to append your html to <tbody> like this:



            $.each(data.listaEstoque, function (i, item) {
            $("#tableestoque tbody").append("<tr"
            + "<td>" + item.empresaProduto.nome + "</td>"
            + "<td>" + item.qtd + "</td>"
            + "</tr>")
            });





            share|improve this answer
























            • Did you even read the comments before answering ?

              – Dekel
              Nov 19 '18 at 13:23











            • @Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)

              – Oleg Nurutdinov
              Nov 19 '18 at 13:31
















            -1














            It looks like you need to append your html to <tbody> like this:



            $.each(data.listaEstoque, function (i, item) {
            $("#tableestoque tbody").append("<tr"
            + "<td>" + item.empresaProduto.nome + "</td>"
            + "<td>" + item.qtd + "</td>"
            + "</tr>")
            });





            share|improve this answer
























            • Did you even read the comments before answering ?

              – Dekel
              Nov 19 '18 at 13:23











            • @Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)

              – Oleg Nurutdinov
              Nov 19 '18 at 13:31














            -1












            -1








            -1







            It looks like you need to append your html to <tbody> like this:



            $.each(data.listaEstoque, function (i, item) {
            $("#tableestoque tbody").append("<tr"
            + "<td>" + item.empresaProduto.nome + "</td>"
            + "<td>" + item.qtd + "</td>"
            + "</tr>")
            });





            share|improve this answer













            It looks like you need to append your html to <tbody> like this:



            $.each(data.listaEstoque, function (i, item) {
            $("#tableestoque tbody").append("<tr"
            + "<td>" + item.empresaProduto.nome + "</td>"
            + "<td>" + item.qtd + "</td>"
            + "</tr>")
            });






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 19 '18 at 13:22









            Oleg NurutdinovOleg Nurutdinov

            358213




            358213













            • Did you even read the comments before answering ?

              – Dekel
              Nov 19 '18 at 13:23











            • @Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)

              – Oleg Nurutdinov
              Nov 19 '18 at 13:31



















            • Did you even read the comments before answering ?

              – Dekel
              Nov 19 '18 at 13:23











            • @Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)

              – Oleg Nurutdinov
              Nov 19 '18 at 13:31

















            Did you even read the comments before answering ?

            – Dekel
            Nov 19 '18 at 13:23





            Did you even read the comments before answering ?

            – Dekel
            Nov 19 '18 at 13:23













            @Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)

            – Oleg Nurutdinov
            Nov 19 '18 at 13:31





            @Dekel users adding comments so fast. Sorry, If my answer give offense to you ;)

            – Oleg Nurutdinov
            Nov 19 '18 at 13:31


















            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%2f53375500%2fload-table-via-list-ajax%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







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini