跟踪数据表中的多页表单

时间:2016-09-12 21:41:52

标签: javascript jquery datatables

我有一个长达几页的订单,用户可以输入大量商品。我试图保持订单总额的总计。

https://jsfiddle.net/kodemonki/9vj98u9m/3/

这是我一直在使用的大部分代码。你可以看到我尝试过的一些东西。

 function recalculate(){
    var qtyArray = new Array();
    var costArray = new Array();
    var total_cost = 0;

    // Iterate over all checkboxes in the table
    // $('input[type="number"].part_qty').each(function(){
    //  // If checkbox doesn't exist in DOM
    //  if(!$.contains(document, this)){
    //      // Create a hidden element 
    //      $(form).append(
    //          $('<input>')
    //              .attr('type', 'hidden')
    //              .attr('name', this.name)
    //              .val(this.value)
    //              .attr('class','part_qty')
    //      );
    //  } 
    // });

    //$('input[type=number].part_qty').each(function(){
    $('input[type=number]').each(function(){
        qtyArray.push(Number($(this).val()));
        //console.log(this);
    });
    $('.part_cost').each(function(){
        costArray.push(Number($(this).html().replace(/[^0-9\.]+/g,"")));

    });

    for(var i = 0;i < qtyArray.length; i++){
        // console.log(qtyArray[i] + isNaN(qtyArray[i]));
        // console.log(costArray[i] + isNaN(costArray[i]));
        total_cost = total_cost + (qtyArray[i] * costArray[i]);
        //console.log(total_cost);
    }   

    total_cost = Math.round(total_cost*100)/100;

    var table = $('#partsList').DataTable();
    var data = table.$('input').serialize();
    // console.log(data);   

    //console.log(qtyArray);
    //console.log(costArray);
    //$(#order_total).html('32532');
    $("#order_total").html('$'+total_cost);
}

不确定为什么分页或总数没有出现在小提琴中。它在我的开发网站上看起来很好。

但是,我不能让总数跟踪页面。我看了几个解决方案,似乎无法得到它。对于表单提交,我添加了已删除的数据,但相同的解决方案似乎不适用于总计。

谢谢。

0 个答案:

没有答案