Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: get Contents of cell for sorting


Message #1 by "Aaron sahlin" <aaronsahlin@y...> on Tue, 13 Aug 2002 22:35:36
----- Original Message -----
From: "Aaron sahlin" <aaronsahlin@y...>
To: "javascript" <javascript@p...>
Sent: Tuesday, August 13, 2002 10:35 PM
Subject: [javascript] get Contents of cell for sorting


> I am trying to implement a sorting routine in javascript.   My table
contains 5 columns, and the 1st
> column has and image and text and the rest of the columns are just text.
>
> I have the sorting working with exception to the column with the <img>
then text in it.  I put in an alert
> message to see what I am getting for the context of that cell and I get
"undefined".  Here is the code
> snippet that is trying to get the value for the cells.
>
>                                           for (var j=1;
j<table.rows[i].cells.length; j++)
> {
> // Can't have row span in record rows ...
> if (table.rows[i].cells[j].rowSpan > 1) return;
> nChildNodes 
> table.rows[i].
> cells[j].firstChild.childNodes.
> length;
>                                                         // this portion
gets the cell values, and for the column with an
>                                                        // image it get
"undefined"
> innerMostNode 
> table.rows[i].
> cells[j].firstChild;
>
> alert(innerMostNode.data)
> while ( nChildNodes != 0)
> {
> innerMostNode 
> innerMostNode.
> firstChild;
> nChildNodes 
> innerMostNode.
> childNodes.
> length;
> }
>
> if (j == 0)
> {
> rowArray[actualNRow] 
> innerMostNode.data;
> }
> else
> {
> rowArray[actualNRow] += recDelimiter +
> innerMostNode.data;
>
> }
> }
>
>
> Any ideas on how I could modify to get the text of the column with the
image, because  that is what
> I want to sort on.
>
> Thanks in advance
The data property only exists for certain types of nodes, not 'img'
elements. If your cell has an image and then text but the others have just
text then I would say:
 if (table.rows[i].cells[j].rowSpan > 1) return;
var oCurrentCell =  table.rows[i].cells[j.];  //Save finding each time...
nChildNodes =oCurrentCell.childNodes.length;
if(nChildNodes > 0)
{
  var sText = oCurrentCell.childNodes[nChildNodes - 1].nodeValue; //This
will get the text part of the last node assuming it is a text node.
}

//continue

Joe



  Return to Index