These examples demonstrate "standard" row selection mode and "single" row selection mode.
Loading... | |||
03/24/1981 | Joe | Jenny | Check out my new pictures |
02/11/1980 | Jane | Jenny | Let's have lunch |
12/12/1978 | Ann | Jenny | Here's the info you requested |
02/11/1974 | Bob | Jenny | RE: Let's have lunch |
02/10/1974 | Charlie | Jenny | Birthday party Saturday |
Data:
1 | YAHOO.example.Data = { |
2 | emails: { |
3 | account:"jenny@yahoo.com", |
4 | currStorage: 10, |
5 | maxStorage: 200, |
6 | messages: [ |
7 | {XID: "9897",Date:new Date(1981, 2, 24),To:"Joe",From:"Jenny",Unread:false,Subject:"Check out my new pictures"}, |
8 | {XID: "7899",Date:new Date(1980, 1, 11),To:"Jane",From:"Jenny",Unread:false,Subject:"Let's have lunch"}, |
9 | {XID: "6789",Date:new Date(1978, 11, 12),To:"Ann",From:"Jenny",Unread:false,Subject:"Here's the info you requested"}, |
10 | {XID: "4996",Date:new Date(1974, 1, 11),To:"Bob",From:"Jenny",Unread:true,Subject:"RE: Let's have lunch"}, |
11 | {XID: "4544",Date:new Date(1974, 1, 10),To:"Charlie",From:"Jenny",Unread:false,Subject:"Birthday party Saturday"} |
12 | ] |
13 | } |
14 | } |
view plain | print | ? |
CSS:
1 | /* custom styles for this example */ |
2 | .yui-skin-sam .yui-dt-body { cursor:pointer; } /* when rows are selectable */ |
3 | #single { margin-top:2em; } |
view plain | print | ? |
Markup:
1 | <div id="standard"></div> |
2 | <div id="single"></div> |
view plain | print | ? |
JavaScript:
1 | YAHOO.util.Event.addListener(window, "load", function() { |
2 | YAHOO.example.RowSelection = new function() { |
3 | var myColumnDefs = [ |
4 | {key:"Date",formatter:YAHOO.widget.DataTable.formatDate, sortable:true}, |
5 | {key:"To", sortable:true}, |
6 | {key:"From", sortable:true}, |
7 | {key:"Subject", sortable:true} |
8 | ]; |
9 | |
10 | this.myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.emails); |
11 | this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; |
12 | this.myDataSource.responseSchema = { |
13 | resultsList: "messages", |
14 | fields: ["Date","To","From","Subject","XID","Date","Attachment"] |
15 | }; |
16 | |
17 | this.standardSelectDataTable = new YAHOO.widget.DataTable("standard", |
18 | myColumnDefs, this.myDataSource, { |
19 | caption:"Standard Row Selection with Support for Modifier Keys" |
20 | }); |
21 | |
22 | // Subscribe to events for row selection |
23 | this.standardSelectDataTable.subscribe("rowMouseoverEvent", this.standardSelectDataTable.onEventHighlightRow); |
24 | this.standardSelectDataTable.subscribe("rowMouseoutEvent", this.standardSelectDataTable.onEventUnhighlightRow); |
25 | this.standardSelectDataTable.subscribe("rowClickEvent", this.standardSelectDataTable.onEventSelectRow); |
26 | |
27 | // Programmatically select the first row |
28 | this.standardSelectDataTable.selectRow(this.standardSelectDataTable.getTrEl(0)); |
29 | // Programmatically bring focus to the instance so arrow selection works immediately |
30 | this.standardSelectDataTable.focus(); |
31 | |
32 | this.singleSelectDataTable = new YAHOO.widget.DataTable("single", |
33 | myColumnDefs, this.myDataSource, { |
34 | caption:"Single-Row Selection with Modifier Keys Disabled", |
35 | selectionMode:"single" |
36 | }); |
37 | |
38 | // Subscribe to events for row selection |
39 | this.singleSelectDataTable.subscribe("rowMouseoverEvent", this.singleSelectDataTable.onEventHighlightRow); |
40 | this.singleSelectDataTable.subscribe("rowMouseoutEvent", this.singleSelectDataTable.onEventUnhighlightRow); |
41 | this.singleSelectDataTable.subscribe("rowClickEvent", this.singleSelectDataTable.onEventSelectRow); |
42 | |
43 | // Programmatically select the first row |
44 | this.singleSelectDataTable.selectRow(this.singleSelectDataTable.getTrEl(0)); |
45 | }; |
46 | }); |
view plain | print | ? |
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.
INFO 4254ms (+0) 8:38:38 AM:
DataTable instance yui-dt1
Post-render routine executed
INFO 4254ms (+0) 8:38:38 AM:
DataTable instance yui-dt1
DataTable rendered
INFO 4254ms (+1) 8:38:38 AM:
DataTable instance yui-dt0
Post-render routine executed
INFO 4253ms (+12) 8:38:38 AM:
DataTable instance yui-dt0
DataTable rendered
INFO 4241ms (+0) 8:38:38 AM:
DataTable instance yui-dt1
Selected [object HTMLTableRowElement]
INFO 4241ms (+1) 8:38:38 AM:
DataTable instance yui-dt1
DataTable message hidden
INFO 4240ms (+0) 8:38:38 AM:
DataTable instance yui-dt1
DataTable rendering...
INFO 4240ms (+0) 8:38:38 AM:
RecordSet instance yui-rs1
Set 5 Record(s) at index 0
INFO 4240ms (+0) 8:38:38 AM:
DataSource instance0
Received live data response for "null"
INFO 4240ms (+0) 8:38:38 AM:
DataSource instance0
Making connection to live data for "null"
INFO 4240ms (+1) 8:38:38 AM:
DataTable instance yui-dt1
DataTable showing message: Loading...
WARN 4239ms (+0) 8:38:38 AM:
DataTable instance yui-dt1
Could not find DragDrop for resizeable Columns
INFO 4239ms (+1) 8:38:38 AM:
DataTable instance yui-dt1
TH cells for 4 keys created
INFO 4238ms (+0) 8:38:38 AM:
RecordSet instance yui-rs1
RecordSet initialized
INFO 4238ms (+0) 8:38:38 AM:
ColumnSet instance yui-cs1
ColumnSet initialized
INFO 4238ms (+1) 8:38:38 AM:
DataTable instance yui-dt0
Selected [object HTMLTableRowElement]
INFO 4237ms (+3) 8:38:38 AM:
DataTable instance yui-dt0
DataTable message hidden
INFO 4234ms (+0) 8:38:38 AM:
DataTable instance yui-dt0
DataTable rendering...
INFO 4234ms (+2) 8:38:38 AM:
RecordSet instance yui-rs0
Set 5 Record(s) at index 0
INFO 4232ms (+0) 8:38:38 AM:
DataSource instance0
Received live data response for "null"
INFO 4232ms (+0) 8:38:38 AM:
DataSource instance0
Making connection to live data for "null"
INFO 4232ms (+1) 8:38:38 AM:
DataTable instance yui-dt0
DataTable showing message: Loading...
WARN 4231ms (+0) 8:38:38 AM:
DataTable instance yui-dt0
Could not find DragDrop for resizeable Columns
INFO 4231ms (+3) 8:38:38 AM:
DataTable instance yui-dt0
TH cells for 4 keys created
INFO 4228ms (+0) 8:38:38 AM:
RecordSet instance yui-rs0
RecordSet initialized
INFO 4228ms (+2) 8:38:38 AM:
ColumnSet instance yui-cs0
ColumnSet initialized
INFO 4226ms (+12) 8:38:38 AM:
DataSource instance0
DataSource initialized
INFO 4214ms (+4214) 8:38:38 AM:
LogReader instance0
LogReader initialized
INFO 0ms (+0) 8:38:34 AM:
global
Logger initialized
Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.
Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings