Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
How to get previous row value in HTML grid using JQuery/Javascript

How to get previous column value in grid using Javascript/JQuery.

The Field A,B and C always input field(Textbox) values. In first row the D,E,F values always will be "NA" and in second row onwards the value of D,E,F should be previous row value of A,B,C as per given below. How to get previous columns value using jQuery.

A   B   C  D  E  F  
--------------------
10  20  30 NA NA NA Edit
40  50  70 10 20 30 Edit
66  27  38 40 50 70 Edit 

As per my below code, I am getting previous row result. But suppose when I click on Edit on second row , then it is reading current column values from A,B,C. It should read previous column values of A,B,C. I have HTML fields to make the grid.

var xyz=0
 $("tbody").find("tr").each(function () {
        var val = $(this).find('td.tdColumnofAText').text();

        if ($(this).find('td.tdColumnofAText').text() > 0) {
                xyz = Number(val);

        }

    });

    $('#txtofDValue').val(xyz);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Consider the following.

$(function() {
  function initTable(table) {
    var cur;
    var next;
    $("tbody tr", table).each(function(index, elem) {
      cur = [
        $("td:eq(0)", this).text().trim(),
        $("td:eq(1)", this).text().trim(),
        $("td:eq(2)", this).text().trim()
      ];
      next = $(this).next();
      if (next !== undefined) {
        $("td:eq(3)", next).html(cur[0]);
        $("td:eq(4)", next).html(cur[1]);
        $("td:eq(5)", next).html(cur[2]);
      }

    });
  }

  initTable($("table"));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <thead>
    <tr>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th>D</th>
      <th>E</th>
      <th>F</th>
      <td>&nbsp;</td>
    </tr>
    <thead>
      <tbody>
        <tr>
          <td>10</td>
          <td>20</td>
          <td>30</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>Edit</td>
        </tr>
        <tr>
          <td>40</td>
          <td>50</td>
          <td>70</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>Edit</td>
        </tr>
        <tr>
          <td>66</td>
          <td>27</td>
          <td>38</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>Edit</td>
        </tr>
      </tbody>
</table>

This loops through each row and collects some values. It then adds it to specific cells in the Next row, if it exists.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda