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

480
Views
Getting Table row ID and Values in jQuery Array

In my web application, I created a table to show some items to the table. In the table, there are nine columns and the last has an editable cell.

enter image description here

The first column includes the Part_Id related to the Part No record and that field is hidden. So I want to get all the Id and data that does not contain the empty values in the `New Order Qty' column and pass all values to the controller.

So on the Create Order button click event, I tried to call this function to took Id and the Order Qty and add them to an array. But only the first record is going to the array. Is there a way to get only the records that contain values in the New Order Qty to array to pass it to the controller?

function createOrder() {

  var Orders = new Array();
  $("#tblParts").each(function() {

    var order = {};
    var partId = this.getElementsByTagName("td")[0];
    var pID = partId.innerText;
    var cellOrder = this.getElementsByTagName("td")[8];
    var cellOrderId = cellOrder.innerText;
    order.Id = pID;
    order.OrderQty = cellOrderId;
    Orders.push(order);

  });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. IDs need to be unique
  2. You have jQuery, use it

const Orders = $("#tableId tbody tr").filter(function() {
  const cells = $(this).find("td");
  return cells.eq(8).text().trim() != ""
}).map(function() {
  const cells = $(this).find("td");
  return {
    [cells.eq(0).text().trim()]: +cells.eq(8).text()
  }
}).get()

console.log(Orders)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="tableId">
  <thead>
    <tr>
      <th>ID</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th>QTY</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>ID 1</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>32</td>
    </tr>
    <tr>
      <td>ID 2</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td>ID 3</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>23</td>
    </tr>

  </tbody>
</table>

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!