Skip to main content
se añadieron 2568 caracteres en el cuerpo
Origen Enlace
DoubleM
  • 1.3k
  • 4
  • 29
  • 70

html

<table id="datatable-buttons" class="table table-striped table-bordered dataTable no-footer dtr-inline" role="grid" aria-describedby="datatable-buttons_info" style="width: 100%;">
                          <thead>
                            <tr role="row">
                                <th class="sorting_asc" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 50px;" aria-sort="ascending" aria-label="Name: activate to sort column descending">#</th>
                                <th class="sorting" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 200px;" aria-label="Position: activate to sort column ascending">Calidad</th>
                                <th class="sorting" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 50px;" aria-label="Office: activate to sort column ascending">Peso</th>
                                <th class="sorting" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 50px;" aria-label="Age: activate to sort column ascending">Cajas</th>
                                <th class="sorting" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 50px;" aria-label="Start date: activate to sort column ascending">Precio</th>
                          </thead>

                            <tbody>
                                <?php if(!empty($calidad)): ?>
                                    <?php foreach($calidad as $calidad): ?>
                                
                                  <tr role="row" class="odd">
                                      <td tabindex="0" class="sorting_1"><input type="hidden"><?php echo $calidad->id; ?></td>
                                      <td><?php echo $calidad->nombre; ?></td>
                                      <td><input type="number" name="peso" placeholder="0" class="form-control peso"></td>
                                      <td><input type="number" name="cajas" placeholder="0" class="form-control cajas"></td>
                                      <td><input type="number" name="precio" placeholder="0" class="form-control precio"></td>
                                    </tr>
                                    <?php endforeach; ?>
                                <?php endif; ?>
                            </tbody>
                    </table>

html

<table id="datatable-buttons" class="table table-striped table-bordered dataTable no-footer dtr-inline" role="grid" aria-describedby="datatable-buttons_info" style="width: 100%;">
                          <thead>
                            <tr role="row">
                                <th class="sorting_asc" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 50px;" aria-sort="ascending" aria-label="Name: activate to sort column descending">#</th>
                                <th class="sorting" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 200px;" aria-label="Position: activate to sort column ascending">Calidad</th>
                                <th class="sorting" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 50px;" aria-label="Office: activate to sort column ascending">Peso</th>
                                <th class="sorting" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 50px;" aria-label="Age: activate to sort column ascending">Cajas</th>
                                <th class="sorting" tabindex="0" aria-controls="datatable-buttons" rowspan="1" colspan="1" style="width: 50px;" aria-label="Start date: activate to sort column ascending">Precio</th>
                          </thead>

                            <tbody>
                                <?php if(!empty($calidad)): ?>
                                    <?php foreach($calidad as $calidad): ?>
                                
                                  <tr role="row" class="odd">
                                      <td tabindex="0" class="sorting_1"><input type="hidden"><?php echo $calidad->id; ?></td>
                                      <td><?php echo $calidad->nombre; ?></td>
                                      <td><input type="number" name="peso" placeholder="0" class="form-control peso"></td>
                                      <td><input type="number" name="cajas" placeholder="0" class="form-control cajas"></td>
                                      <td><input type="number" name="precio" placeholder="0" class="form-control precio"></td>
                                    </tr>
                                    <?php endforeach; ?>
                                <?php endif; ?>
                            </tbody>
                    </table>
Origen Enlace
DoubleM
  • 1.3k
  • 4
  • 29
  • 70

porque no me suma las columnas

Estoy intentando sumar la columna peso y mostrarlo en mi <span id="ptotal"> el problema es que siempre me retorna cero.

introducir la descripción de la imagen aquí

$(document).on('keyup','#datatable-buttons input.peso',function(){
                peso = $(this).val();

                sumar();
        });

    function sumar(){
            pesostotal = 0;
            $("#datatable-buttons tr").each(function(){
                pesostotal = pesostotal + $(this).find('td:eq(2)').text();
                alert(pesostotal); // lo puse por debugger Muestra 0 siempre!
            });
            $('#ptotal').text(pesostotal);
        }