|
||
| Inside Technique : Table Highlights : Highlights Details The table on the first page is defined using the COL, TH, and other table elements as follows:
The appearance of the table and the highlights are specified using CSS. These properties
can be modified to create your own custom table.
The .cover and .rover styles define the column and row highlights. If desired, you can
define the same style for both highlights by having them share a single style sheet rule:
Now, the last step is to apply the appropriate code to the table. If you look back at the HTML
for the table, you will notice that an onmouseover and onmouseout event handler is defined. Each time
the mouse enters and exits an HTML element within the table, the function checkHighlight is called. This
function examines what row or column the mouse is over and highlights it. The complete code for this function
is listed below:
The checkHighlight function works by first finding the cell the mouse is over. The getElement() function is designed to walk up the HTML document from the specified element and returns any elements that match the passed in set of tag names. For example, the first call that passes in "TH" and "TD" locates and returns the cell the mouse is over (the srcElement represents the HTML element that contains the text the mouse is over). This function is used a few times to next locate the row, and eventually the table for the mouse position. Next, if the mouse is over a TH cell, and column highlighting is enabled, the column is highlighted. Highlighting columns requires a little work because the table does not expose a columns collection. Instead, the cellIndex is used to determine what column the cell is in, and then the appropriate COL element is found that represents the cell's column. When the mouse is over a TD cell and row highlighting is enabled, the row can be found more directly by looking at the parent of the TD element. Unlike working with columns, there is no need to locate the row indirectly. Next, we finish this article with a demonstration on how column highlighting may be used with databinding. In the following example, we have a (shortened) list of our favorite links. As the mouse moves over the column headers, the columns are highlighted. By clicking on a column header, the column will be sorted. Page 1:Table Highlights © 1997-2000 InsideDHTML.com, LLC. All rights reserved. |