2016-03-28 5 views
0

У меня есть функция, которая вычисляет общее количество и общее количество. Моя проблема здесь заключается в том, что я хочу отображать общее количество в каждом подразделении, но это будет тот же результат. Я хочу, чтобы заголовок 1 был общим 37,00, а Header 2 - 99,00. Вот скриншот. enter image description hereКак показать общее количество в каждом подразделении

И вот мой код.

$('.pricing_level').on('change', function(e){ 
    var pricing_level_id = e.target.value; 
    var customer_id = $('.customer ').val(); 

    $('tbody.subcontent tr').each(function(){ 
     var item_id = $(this).closest('tr').find(".details_itemid").val(); 
     var category_id = $(this).closest('tr').find(".details_category_id").val(); 
     var subcategory_id = $(this).closest('tr').find(".details_subcategory_id").val(); 
     var that = this; 

     $.get('/dev/api/itempricinglevel?item_id=' + item_id + '&pricinglevel_id=' + pricing_level_id, function(itempricinglevel){ 
      var std = parseFloat(itempricinglevel.std); 
      var min = parseFloat(itempricinglevel.min); 
      var max = parseFloat(itempricinglevel.max); 

      $(that).closest('tr').find('.details_unitprice').val(std); 

      //Here's the code to display the sub-total in every division 
      var d_qty = $(that).closest('tr').find(".details_qty").val(); 
      var d_netprice = $(that).closest('tr').find(".details_netunitprice").val(); 
      var total = d_qty * d_netprice; 
      var totalAmt = total.toFixed(2); 

      $(that).closest('tr').find(".details_total").val(totalAmt); 
      grandtotal(); 
      var thisloc = $(that).parent().parent().parent().parent().find('.total'); 
      var inloc = $(that).parent().parent().parent().parent().find('.stotal'); 
      var eachloc = $(that).parent().parent().parent().find('.details_total'); 
      subtotal(thisloc, eachloc, inloc); 
      //------------------------------------------------------------ 
     }) 

    }) 
}) 

И вот моя субтотальная функция

function subtotal(thisloc, eachloc, inloc){ 
    var headertotal = 0; 
    eachloc.each(function(){ 
     var price = $(this).val(); 
     headertotal += parseFloat(price); 
     $(thisloc).text((headertotal).toFixed(2)); 
     $(inloc).val((headertotal).toFixed(2)); 
    }); 
} 

Вот HTML код к югу от общего количества.

$('tbody.content').prepend('<div class="groupborder" style="border-color:#333333;"><tr><td> \ 
      <table class="tables_details" style="width:100%;">\ 
       <th id="groups" data-id="'+headcount+'" style="background-color: #333333; width: 1250px;" > \ 
       <label style="display:inline-block;float:left; margin-left:900px; width:60px; font-weight: bold; color:#FFFFFF;">Sub-total: </label> \ 
       <label class="head" style="display: block; margin-left: -930px; float: left; font-weight: bold; color:#FFFFFF;">HEADER '+headcount+'</label> \ 
       <input type="text" name="header_name[]" class="edit-input" style="height: 20px; display: none; margin-left: -930px; float: left; padding-left:5px;" value="HEADER '+headcount+'"/> \ 
       <input name="header_id[]" type="hidden" value="'+headcount+'"> \ 
       <a href="" class="rm-header fa fa-times-circle fa-lg" style="float:right; margin-right:5px; margin-top:5px"></a> \ 
       <label style="display:inline-block; float:right; margin-right:18px; font-weight: bold; color:#FFFFFF;" class="total">0.00</label> \ 
       <input name="header_subtotal[]" class="stotal" type="hidden" value="0.00"> </th> \ 
       <tbody class="subcontent tbody"></tbody>\ 
      </table>\ 
     </td>\ 
     </tr></div>'); 
+1

вы можете поделиться 'функцию subtotal', а также ваше мнение –

+0

функцию подытог (thisloc, eachloc, inloc) { вар headertotal = 0; eachloc.each (функция() { вар цена = $ (это) .val(); headertotal + = parseFloat (цена); $ (thisloc) .text ((headertotal) .toFixed (2)); $ (inloc) .val ((headertotal) .toFixed (2)); }); } –

+0

Можете ли вы обновить свой вопрос с помощью HTML? –

ответ

0

Внутри ави есть.

var dataid = $(that).closest('tr').find('.details_total').data('total_id'); 
subtotal2(dataid); 

И вам нужно сделать еще одну промежуточную функцию.

function subtotal2(dataid){ 
    var headertotal = 0; 
    $('.details_total_'+dataid+'').each(function(){ 
     var price = $(this).val(); 
     headertotal += parseFloat(price); 
     $('#total_'+dataid+'').text((headertotal).toFixed(2)); 
     $('#total_'+dataid+'').val((headertotal).toFixed(2)); 

    }); 
} 
Смежные вопросы