0
contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(reportCriteria),
            success: function (response) {
                console.log(response);
                if (response.reportResult != null) {
                    for (var i = 0 ; i < response.reportResult.length; i++) {
                        var data = "<tr>" +
                            "<td class='reportTbl'>" + moment(new Date(parseInt(response.reportResult[i].InvoiceDate.substr(6))).toLocaleDateString()).format('YYYY-MMMM-DD') + "</td>" +
                             "<td class='reportTbl'>" + response.reportResult[i].InvoiceNumber + "</td>" +
                             "<td class='reportTbl'>" + response.reportResult[i].TotalValueWithVAT + "</td>" +
                             "<td class='reportTbl'>" + response.reportResult[i].**PartialPayments.ChequeNumber** + "</td>" +
                            "</tr>";
                        $('#completedPaymentReportTbl tbody').after(data);
                    }
                }
            }

"PartialPayments" is the inner model how can i append the data

1 Answer 1

1

After messing with a JQuery sandbox I found that $('#completedPaymentReportTbl').append(data); should work for you. As reported in Appending rows to table, Jquery 1.4+ will automatically work out that you have a tbody there and know to append the rows inside the tbody.

I have two suggestions with things that may help prevent this bug and/or future bugs:

  1. Try and introduce c# variables in your model or static variables for things like table names. Instead of typing #completedPaymentReportTbl, you'd type something like '@completedPaymentReportTableId' (example is for Razor templates). This will keep your table HTML and your JQuery "in sync".
  2. Instead of sending back the information of your model and constructing the row in your javascript, render the row on the server side and send back the HTML of the row. This ensures that when you change the row structure, all the rows will be consistent.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.