Skip to content
Loading
Display Grand Total at the Bottom of a Table in JQUERYand your jquery code goes like this 
  1. $(document).ready(function () {    
  2.         var tr;    
  3.          var grandTotal = 0;  
  4.         $.getJSON("/QuotationMgt/GetQuotationDetails"function (json) {    
  5.             $.each(json, function (i, emp) {    
  6.                 var empid = emp.Id;    
  7.                 tr = $('');    
  8.                 tr.append("" + emp.Id + "");    
  9.                 tr.append("" + emp.damageName + "");    
  10.                 tr.append("" + emp.damageCondition + "");    
  11.                 tr.append("" + emp.lvlCode + "");    
  12.                 tr.append("" + emp.laborCost + "");    
  13.                 tr.append("" + emp.partsCost + "");    
  14.                 tr.append("" + emp.totalCost + "");    
  15.                 tr.append("" + " + empid + ">Delete");    
  16.                 grandTotal = grandTotal + emp.totalCost;  
  17.                 $('#tblEmployee').append(tr);    
  18.             });    
  19.            $("#lblTotal").text(grandTotal);  
  20.         });    
  21.     
  22.         $('#tblEmployee').on('click''td a.delete'function () {    
  23.             var deleteUrl = $(this).attr("href");    
  24.             if (confirm("Are you sure wants to delete?")) {    
  25.                 $.ajax({    
  26.                     url: deleteUrl, dataType: "json", type: "POST", contentType: "application/json",    
  27.                     error: function (err) { alert('Unable to delete record.'); },    
  28.                     success: function (response) {    
  29.                           
  30.     
  31.                         window.location.href = "/QuotationMgt/CreateQuotationDetail/" + @ViewBag.quotationNo;    
  32.                     }    
  33.                 });    
  34.             }    
  35.         });    
  36.     });    
+1
  • Rajanikant Hawaldar
    check this 
     as per your requirement
    https://techbrij.com/sum-total-avg-table-footer-asp-net-mvc-razor 
     
    this one is by using css to table column and change code accordingly
     
    https://stackoverflow.com/questions/27017507/how-to-get-a-sum-of-column-of-gridview-using-javascript 
    0
  • Jes Sie
    Hi Rajanikant, thanks for your reply. But, this is not asp.net webforms. This is MVC.
    0
  • Rajanikant Hawaldar
    Hi Dear,
     
     
    1. Int32 tot = 0;   
    2. protected void Dg_Source_RowDataBound(object sender, GridViewRowEventArgs e)  
    3. {  
    4.     if (e.Row.RowType == DataControlRowType.DataRow)  
    5.     {  
    6.         tot = tot + Convert.ToInt32(e.Row.Cells[1].Text);  
    7.         lblSum.Text = tot.ToString();  
    8.     }  
    9. }  
    0