Hold On

Hold On

  • 1.2k
  • 722
  • 73.2k

Display Grand Total at the Bottom of a Table in JQUERY

Jul 28 2019 10:38 PM
I have create an MVC project that will display the details of a quotation to a table using JQuery. Below is my mark-up and the jquery itself:
  1. <div class="card-body text-secondary">  
  2.                 <div class="table-responsive-sm">  
  3.                     <table id="tblEmployee" class="table  table-bordered table-hover">  
  4.                         <thead>  
  5.                             <tr>  
  6.                                 <th>Reference #</th>  
  7.                                 <th>Damage Name</th>  
  8.                                 <th>Damage Condition</th>  
  9.                                 <th>Level Code</th>  
  10.                                 <th>Labot Cost</th>  
  11.                                 <th>Parts Cost</th>  
  12.                                 <th>Total Cost</th>  
  13.                                 <th>Action</th>  
  14.                             </tr>  
  15.                         </thead>  
  16.                         <tbody></tbody>  
  17.                     </table>  
  18.                 </div>  
  19.             </div>  
  1. $(document).ready(function () {  
  2.         var tr;  
  3.         $.getJSON("/QuotationMgt/GetQuotationDetails"function (json) {  
  4.             $.each(json, function (i, emp) {  
  5.                 var empid = emp.Id;  
  6.                 tr = $('<tr/>');  
  7.                 tr.append("<td class='Id'>" + emp.Id + "</td>");  
  8.                 tr.append("<td class='damageName'>" + emp.damageName + "</td>");  
  9.                 tr.append("<td class='damageCondition'>" + emp.damageCondition + "</td>");  
  10.                 tr.append("<td class='lvlCode'>" + emp.lvlCode + "</td>");  
  11.                 tr.append("<td class='text-right'>" + emp.laborCost + "</td>");  
  12.                 tr.append("<td class='text-right'>" + emp.partsCost + "</td>");  
  13.                 tr.append("<td class='text-right'>" + emp.totalCost + "</td>");  
  14.                 tr.append("<td>" + "<a Onclick='return false;' class='delete btn btn-sm btn-danger' href=/QuotationMgt/DeleteQuoteItem/" + empid + ">Delete</a>");  
  15.                 $('#tblEmployee').append(tr);  
  16.             });  
  17.         });  
  18.   
  19.         $('#tblEmployee').on('click''td a.delete'function () {  
  20.             var deleteUrl = $(this).attr("href");  
  21.             if (confirm("Are you sure wants to delete?")) {  
  22.                 $.ajax({  
  23.                     url: deleteUrl, dataType: "json", type: "POST", contentType: "application/json",  
  24.                     error: function (err) { alert('Unable to delete record.'); },  
  25.                     success: function (response) {  
  26.                         
  27.   
  28.                         window.location.href = "/QuotationMgt/CreateQuotationDetail/" + @ViewBag.quotationNo;  
  29.                     }  
  30.                 });  
  31.             }  
  32.         });  
  33.     });  
 Below is the sample result and what I wanted is the GRAND TOTAL to be displayed at the bottom
 if this is a gridview in a webform, I can simply use the RowDatabound event to get the grand total. I am just new in MVC and obviously struggling in JQuery.

Any help will be much appreciated.  

Answers (8)