YUI Library Home

YUI Library Examples: DataTable Control: Basic Example

DataTable Control: Basic Example

A demonstration of the DataTable's basic feature set.

DataTable Caption
po-0167
03/24/1980
1
$4.00
A Book About Nothing
po-0783
01/03/1983
0
$12.12
The Meaning of Life
po-0297
12/12/1978
12
$1.25
This Book Was Meant to Be Read Aloud
po-1482
03/11/1985
6
$3.50
Read Me Twice

Sample Code for this Example

Data:

1YAHOO.example.Data = { 
2    bookorders: [ 
3        {id:"po-0167", date:new Date(1980, 2, 24), quantity:1, amount:4, title:"A Book About Nothing"}, 
4        {id:"po-0783", date:new Date("January 3, 1983"), quantity:null, amount:12.12345, title:"The Meaning of Life"}, 
5        {id:"po-0297", date:new Date(1978, 11, 12), quantity:12, amount:1.25, title:"This Book Was Meant to Be Read Aloud"}, 
6        {id:"po-1482", date:new Date("March 11, 1985"), quantity:6, amount:3.5, title:"Read Me Twice"} 
7    ] 
8
view plain | print | ?

CSS:

1.yui-skin-sam .yui-dt-liner { white-space:nowrap}  
2
view plain | print | ?

Markup:

1<div id="basic"></div> 
view plain | print | ?

JavaScript:

1YAHOO.util.Event.addListener(window, "load"function() { 
2    YAHOO.example.Basic = function() { 
3        var myColumnDefs = [ 
4            {key:"id", sortable:true, resizeable:true}, 
5            {key:"date", formatter:YAHOO.widget.DataTable.formatDate, sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC},resizeable:true}, 
6            {key:"quantity", formatter:YAHOO.widget.DataTable.formatNumber, sortable:true, resizeable:true}, 
7            {key:"amount", formatter:YAHOO.widget.DataTable.formatCurrency, sortable:true, resizeable:true}, 
8            {key:"title", sortable:true, resizeable:true
9        ]; 
10 
11        var myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.bookorders); 
12        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; 
13        myDataSource.responseSchema = { 
14            fields: ["id","date","quantity","amount","title"
15        }; 
16 
17        var myDataTable = new YAHOO.widget.DataTable("basic"
18                myColumnDefs, myDataSource, {caption:"DataTable Caption"}); 
19                 
20        return { 
21            oDS: myDataSource, 
22            oDT: myDataTable 
23        }; 
24    }(); 
25}); 
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 3075ms (+0) 11:50:19 AM:

DataTable instance yui-dt0

Post-render routine executed

INFO 3075ms (+5) 11:50:19 AM:

DataTable instance yui-dt0

DataTable rendered

INFO 3070ms (+3) 11:50:19 AM:

DataTable instance yui-dt0

DataTable message hidden

INFO 3067ms (+0) 11:50:19 AM:

DataTable instance yui-dt0

DataTable rendering...

INFO 3067ms (+1) 11:50:19 AM:

RecordSet instance yui-rs0

Set 4 Record(s) at index 0

INFO 3066ms (+0) 11:50:19 AM:

DataSource instance0

Parsed array data is {results => [{title => A Book About Nothing, amount => 4, quantity => 1, date => Mon Mar 24 1980 00:00:00 GMT+0000 (Coordinated Universal Time), id => po-0167}, {title => The Meaning of Life, amount => 12.12345, quantity => , date => Mon Jan 03 1983 00:00:00 GMT+0000 (Coordinated Universal Time), id => po-0783}, {title => This Book Was Meant to Be Read Aloud, amount => 1.25, quantity => 12, date => Tue Dec 12 1978 00:00:00 GMT+0000 (Coordinated Universal Time), id => po-0297}, {title => Read Me Twice, amount => 3.5, quantity => 6, date => Mon Mar 11 1985 00:00:00 GMT+0000 (Coordinated Universal Time), id => po-1482}]}

INFO 3066ms (+1) 11:50:19 AM:

DataSource instance0

Received live data response for "null"

INFO 3065ms (+0) 11:50:19 AM:

DataSource instance0

Making connection to live data for "null"

INFO 3065ms (+4) 11:50:19 AM:

DataTable instance yui-dt0

DataTable showing message: Loading...

INFO 3061ms (+3) 11:50:19 AM:

DataTable instance yui-dt0

TH cells for 5 keys created

INFO 3058ms (+0) 11:50:19 AM:

RecordSet instance yui-rs0

RecordSet initialized

INFO 3058ms (+1) 11:50:19 AM:

ColumnSet instance yui-cs0

ColumnSet initialized

INFO 3057ms (+28) 11:50:19 AM:

DataSource instance0

DataSource initialized

INFO 3029ms (+3029) 11:50:19 AM:

LogReader instance0

LogReader initialized

INFO 0ms (+0) 11:50:16 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 © 2010 Yahoo! Inc. All rights reserved.

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