YUI recommends YUI 3.

YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.

YUI Library Home

YUI Library Examples: DataTable Control: Highlighting Cells, Rows, or Columns

DataTable Control: Highlighting Cells, Rows, or Columns

Page
VisitsThisMonth
VisitsThisYear
ViewsThisMonth
ViewsThisYear
Example: Cell Highlighting
home.html
20
400
44
657
blog.html
24
377
97
567
contact.html
32
548
42
543
about.html
8
465
12
946
pagenotfound.html
0
0
0
0
Page
VisitsThisMonth
VisitsThisYear
ViewsThisMonth
ViewsThisYear
Example: Row Highlighting
home.html
20
400
44
657
blog.html
24
377
97
567
contact.html
32
548
42
543
about.html
8
465
12
946
pagenotfound.html
0
0
0
0
Page
VisitsThisMonth
VisitsThisYear
ViewsThisMonth
ViewsThisYear
Example: Column Highlighting
home.html
20
400
44
657
blog.html
24
377
97
567
contact.html
32
548
42
543
about.html
8
465
12
946
pagenotfound.html
0
0
0
0

Sample Code for this Example

Data:

1YAHOO.example.Data.webstats = [ 
2    ["home.html",20,400,44,657], 
3    ["blog.html",24,377,97,567], 
4    ["contact.html",32,548,42,543], 
5    ["about.html",8,465,12,946], 
6    ["pagenotfound.html",0,0,0,0] 
7
view plain | print | ?

CSS:

1/* No custom CSS. */ 
view plain | print | ?

Markup:

1<div id="cell"></div> 
2<div id="row"></div> 
3<div id="column"></div> 
view plain | print | ?

JavaScript:

1YAHOO.util.Event.addListener(window, "load"function() { 
2    YAHOO.example.Highlighting = new function() { 
3        var myColumnDefs = [ 
4            {key:"Page"}, 
5            {key:"VisitsThisMonth"}, 
6            {key:"VisitsThisYear"}, 
7            {key:"ViewsThisMonth"}, 
8            {key:"ViewsThisYear"
9        ]; 
10 
11        this.myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.webstats); 
12        this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; 
13        this.myDataSource.responseSchema = { 
14            fields: ["Page","VisitsThisMonth","VisitsThisYear","ViewsThisMonth","ViewsThisYear"
15        }; 
16 
17        this.cellHighlightDataTable = new YAHOO.widget.DataTable("cell"
18                myColumnDefs, this.myDataSource, { 
19                    caption:"Example: Cell Highlighting" 
20                }); 
21        // Enable cell highlighting 
22        this.cellHighlightDataTable.subscribe("cellMouseoverEvent"this.cellHighlightDataTable.onEventHighlightCell); 
23        this.cellHighlightDataTable.subscribe("cellMouseoutEvent"this.cellHighlightDataTable.onEventUnhighlightCell); 
24 
25        this.rowHighlightDataTable = new YAHOO.widget.DataTable("row"
26                myColumnDefs, this.myDataSource, { 
27                    caption:"Example: Row Highlighting" 
28                }); 
29        // Enable row highlighting 
30        this.rowHighlightDataTable.subscribe("rowMouseoverEvent"this.rowHighlightDataTable.onEventHighlightRow); 
31        this.rowHighlightDataTable.subscribe("rowMouseoutEvent"this.rowHighlightDataTable.onEventUnhighlightRow); 
32 
33        this.colHighlightDataTable = new YAHOO.widget.DataTable("column"
34                myColumnDefs, this.myDataSource, { 
35                    caption:"Example: Column Highlighting" 
36                }); 
37        // Enable Column highlighting 
38        this.colHighlightDataTable.subscribe("theadCellMouseoverEvent"this.colHighlightDataTable.onEventHighlightColumn); 
39        this.colHighlightDataTable.subscribe("theadCellMouseoutEvent"this.colHighlightDataTable.onEventUnhighlightColumn); 
40    }; 
41}); 
view plain | print | ?

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

YUI Logger Output:

Logger Console

INFO 80ms (+80) 2:19:04 AM:

LogReader instance0

LogReader initialized

INFO 0ms (+0) 2:19:04 AM:

global

Logger initialized

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

More DataTable Control Resources:

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings