How to calculate total of all row in jquery

Majeed

I have some row with some product data.i can add more row dynamically by jQuery, i have calculate total for each row in the end . now I want to calculate grand total of all row. i have tired but it's always show the last row total in grandtotal. please see the picture.

enter image description here

Here is my jquery part.

 //calculation here

$('#dsp').on('input','.ctn',function(){
     var cal=$(this).val();
     var gparent=$(this).closest('.row');
     var unitp=gparent.find('.u_price').val();
     var unitpctn=gparent.find('.unit_pctn').val();
     var pcs=gparent.find('.pcs').val();
    //alert(pcs);
    var total=(((parseInt(unitpctn)*parseInt(cal)) + parseInt(pcs))*parseInt(unitp));

       gparent.find('.t_amt').val(total);

       //grand total
       var gtotal=0;
       var gtotal=parseInt(gtotal)+parseInt(total)
       //alert(gtotal);
       $('#tot').html(gtotal);


});

 $('#dsp').on('input','.pcs',function(){
     var pcs=$(this).val();
     var gparent=$(this).closest('.row');
     var unitp=gparent.find('.u_price').val();
     var unitpctn=gparent.find('.unit_pctn').val();
     var ctn=gparent.find('.ctn').val();
    //alert(pcs);
    var total=(((parseInt(unitpctn)*parseInt(ctn)) + parseInt(pcs))*parseInt(unitp));

       gparent.find('.t_amt').val(total);

       //grand total
       var gtotal=0;
       var gtotal=parseInt(gtotal)+parseInt(total)
       //alert(gtotal);
       $('#tot').html(gtotal);


});

Here is my view part.

   <div id="dsp">
  <div class="row">
    <div class="col-md-2">
      <select name="p_name[]" class="form-control p_name">
      <option value="">-Select Product-</option>
      @foreach($products as $product)
      <option value="{{$product->product_id}}">{{$product->name}}</option>
      @endforeach
    </select>
    </div>
    <div class="col-md-2">
      <input type="text" name="p_code[]" class="form-control p_code">
    </div>
    <div class="col-md-2">
      <input type="text" name="unit_pctn[]" class="form-control unit_pctn" value="0">
    </div>
    <div class="col-md-2">
      <input type="text" name="u_price[]" class="form-control u_price" value="0">
    </div>
    <div class="col-md-1">
      <input type="text" name="ctn[]" class="form-control ctn" value="0">
    </div>
    <div class="col-md-1">
      <input type="text" name="pcs[]" class="form-control pcs" value="0">
    </div>
    <div class="col-md-2">
      <input type="text" name="t_amt[]" class="form-control t_amt" value="0">
    </div>

  </div>&nbsp;
</div>
            <div class="row" id="nep"></div>
             <div class="row">
                       <div class="col-md-10"></div>
                     <div class="col-md-2">GrandTotal:<h5 id="tot">0</h5></div>
                   </div>
Milan Chheda

Here is a small function to help you calculate the grand total:

function getGrandTotal() {
  var total = 0;
  $(".t_amt").each(function() {
    total += parseFloat($(this).val()) || 0;
  });
  return total;
}

You need to call above function on change of individual total OR on updating individual totals. Simply call the function and it would return you grand total.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jquery to calculate total of table row

From Dev

Calculate total value in table row, JavaScript jQuery

From Dev

How to calculate total row heights of listView in android?

From Dev

How to calculate a total for a given condition on each row?

From Dev

How to calculate the final total Jquery inventory form

From Dev

How to calculate total of a row in a table when quantity changes

From Dev

How to dynamically add a column and row to calculate total in each cell in knockout

From Dev

How to calculate summary of result in Total result from table row

From Dev

How do I calculate the total and average of all dice rolls?

From Dev

How to get all the values of one column and calculate a total

From Dev

How to calculate multiplication of each row and show it with jquery

From Dev

How to calculate multiplication of each row and show it with jquery

From Dev

How to calculate % of total in MySQL

From Dev

How to calculate % of total in MySQL

From Dev

Javascript: how to calculate the total

From Dev

How to calculate sum of all rows with jQuery?

From Dev

jquery calculate total with quantity and steps

From Dev

jquery calculate total amount of bill

From Dev

How to display total of a column in the last row of a datatable generated using jQuery?

From Dev

SSRS calculate percentage of column based on row total

From Dev

VBA Calculate Total Weekdays for Entire Row

From Dev

Calculate all numbers from a Multiple selection return the total sum Multiselect + jQuery

From Dev

Update total in table row with jquery

From Dev

Update total in table row with jquery

From Dev

How to calculate the total of a sum in JSTL

From Dev

How to calculate "running total" in SQL

From Dev

How to calculate total price in php

From Dev

how to calculate total Sum in Excel

From Dev

How to calculate the total distance traveled?

Related Related

  1. 1

    Jquery to calculate total of table row

  2. 2

    Calculate total value in table row, JavaScript jQuery

  3. 3

    How to calculate total row heights of listView in android?

  4. 4

    How to calculate a total for a given condition on each row?

  5. 5

    How to calculate the final total Jquery inventory form

  6. 6

    How to calculate total of a row in a table when quantity changes

  7. 7

    How to dynamically add a column and row to calculate total in each cell in knockout

  8. 8

    How to calculate summary of result in Total result from table row

  9. 9

    How do I calculate the total and average of all dice rolls?

  10. 10

    How to get all the values of one column and calculate a total

  11. 11

    How to calculate multiplication of each row and show it with jquery

  12. 12

    How to calculate multiplication of each row and show it with jquery

  13. 13

    How to calculate % of total in MySQL

  14. 14

    How to calculate % of total in MySQL

  15. 15

    Javascript: how to calculate the total

  16. 16

    How to calculate sum of all rows with jQuery?

  17. 17

    jquery calculate total with quantity and steps

  18. 18

    jquery calculate total amount of bill

  19. 19

    How to display total of a column in the last row of a datatable generated using jQuery?

  20. 20

    SSRS calculate percentage of column based on row total

  21. 21

    VBA Calculate Total Weekdays for Entire Row

  22. 22

    Calculate all numbers from a Multiple selection return the total sum Multiselect + jQuery

  23. 23

    Update total in table row with jquery

  24. 24

    Update total in table row with jquery

  25. 25

    How to calculate the total of a sum in JSTL

  26. 26

    How to calculate "running total" in SQL

  27. 27

    How to calculate total price in php

  28. 28

    how to calculate total Sum in Excel

  29. 29

    How to calculate the total distance traveled?

HotTag

Archive