I want to populate a list of objects based on an HTML table. Let's say I have the following class:
class Employee { String name; String department; num salary; ...methods }
And in my HTML, I have the following table:
<table class="table" id="employeeTable"> <thead> <tr> <th>Name <th>Departament <th>Salary <tbody id="employeeTableBody"> <tr> <td> John <td> 1 <td> 1500 <tr> <td> Mary <td> 2 <td> 2500 ...etc </table>
So, how can I query a table, get its rows, and then get its cells to populate my list of employees (in this case)?
I tried using something like:
TableElement table = query("#employeesTable"); Element tableBody = query("#employeesTableBody");
But I could not find the correct method in the TableElement or Element to return a TableRowElement or, possibly, its cells. I also tried to get child nodes, but without success.
The pseudo-algorithm for performing this task will be something like this:
1. Get the table 2. For each row of the table 2.a Create a new Employee object based on the value of each cell of the row. 2.b Append this object to the Employee List. 3. End
source share