Read a specific column of the prototype table

I need to read all the values ​​of the first column of an HTML table, and I do not want to use DOM methods. I would like to get a simpler solution using Prototype or YUI.

Note. The table is generated by grid widgets provided by an external team. Therefore, we cannot be sure which ID or Classnames are used.

In short, I would like something like:

For each row in table XXX value = row.column[1].value do something with value ... End For 

Thank you in advance

+1
javascript prototypejs
Feb 18 '09 at 22:49
source share
4 answers

You should be able to do something like $$ ('tr td: first-child'), which should get the first td from each tr. You can then use .innerHTML to get the value.

+2
Feb 20 '09 at 15:24
source share

maybe $$('tr') might work. It returns an array of elements based on the CSS rule .

+1
Feb 18 '09 at 22:54
source share

Prototype use

 $('thetable').childElements()[0].childElements().invoke('firstDescendant'); 

All this cascades. The first table $ ('tabletable') gets the table. I know you need a minimal DOM, but obviously you will need to identify the table.

The second one takes all the children as an array and captures the first, which is the tbody element.

Then it captures the children of these elements, which provide an array of table rows.

The last call calls () calls a function for each element in this array. In this case, firstDescendant.

+1
Feb 20 '09 at 22:45
source share

this will give you an array of all text values ​​in the first column

 var arr = $$('tr:first-child').pluck('innerText'); 

pluck

$$

0
Feb 20 '09 at 23:01
source share



All Articles