Sum total of columns

39 views
Skip to first unread message

Dionis Matos

unread,
Jun 13, 2018, 12:06:56 PM6/13/18
to KnockoutJS
Hello all,

I'm trying to have the sum total of a two columns and then display that on the bottom of the page. 

Here is my code: 


self.buscarReporteDetalle = function () {
        var url = pathApi + "apisublaborrealizada/obtenerreporteDetalle";
        self.listaReporte.removeAll();
        if ($("#frmReporte").valid()) {
            disableBottonForm("frmReporte", "btnBuscar", "lmReporte");
            //$('.tableDT').DataTable().clear().destroy();
            $.post(url, $("#frmReporte").serialize(), function (data) {

               

                if (data["estatus"]) {
                    $.each(data["resultado"], function (key, item) {
                        var estatus = (item.Estatus == "A") ? "Aprobada" : ((item.Estatus == "P") ? pendiente : ((item.Estatus == "I") ? inactivo : ((item.Estatus == "PO") ? "Posteada" : inactivo)));
                        item.Estatus = { icono: estatus, valor: item.Estatus };
                        item.Fecha = toShortDateString(item.Fecha);
                        item.Precio = item.Precio.formatMoney(2, '.', ',');
                        item.Monto = (item.Precio * item.Cantidad);
                        item.Monto = item.Monto.formatMoney(2, '.', ',');

                        // monto Total

                       

                        item.MontoTotal += (item.Precio * item.Cantidad); 
                        item.CantidadTotal += item.Cantidad;
                        
                        //item.FechaRegistrada = toShortDateString(item.FechaRegistrada);
                        self.listaReporte.push(item);
                    });

                    if (self.listaReporte().length > 0) {
                        self.Fecha($('#FechaInicio').val() + " - " + $('#FechaFin').val());
                    }
                    else {
                        mostrarToastr("No se han encontrado resultados", "W");
                    }

                } else {
                    mostrarToastr(data["mensaje"], "E");
                }
                enableBottonForm("frmReporte", "btnBuscar", "lmReporte");
            }, "json")
                .fail(function (d) {
                    enableBottonForm("frmReporte", "btnBuscar", "lmReporte");
                    mostrarToastr(d.responseText, "E");
                });
        } else {
            enableBottonForm("frmReporte", "btnBuscar", "lmReporte");
        }
    }
            <table class="table table-hover">
                <thead>
                    <tr bgcolor="#f5f5f5">
                        @*<th>@Idioma.Fecha</th>*@
                        @*<th>@Idioma.Numero</th>*@
                        <th>@Idioma.Empleado</th>
                        <th>@Idioma.Campo</th>
                        <th>@Idioma.SubLabor</th>
                        <th>@Idioma.Precio</th>
                        <th>@Idioma.Cantidad</th>
                        <th>@Idioma.Monto</th>
                        <th>@Idioma.Estatus</th>
                    </tr>
                </thead>
                <tbody data-bind="foreach:listaReporte">
                    <tr>
                        @*<td data-bind="html: Fecha"></td>*@
                        @*<td data-bind="html: Numero"></td>*@
                        <td data-bind="html: Empleado"></td>
                        <td data-bind="html: Campo"></td>
                        <td data-bind="html: SubLabor"></td>
                        <td data-bind="html: Precio"></td>
                        <td data-bind="html: Cantidad"></td>
                        <td data-bind="html: Monto"></td>
                        <td data-bind="html: Estatus.icono"></td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="5"><b>Total:</b></td>
                        <td data-bind="html:CantidadTotal"></td>
                        <td data-bind="html: MontoTotal"></td>
                    </tr>
                </tfoot>
            </table>




Noirabys

unread,
Jun 15, 2018, 5:43:24 AM6/15/18
to KnockoutJS
hi,
iterate over the values you want to sum. what exactly is your problem ?
you can call a method in the model or global function to calculate it.
html: pleaseCalculateASumForMeFor
Reply all
Reply to author
Forward
0 new messages