Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!