A demonstration of the DataTable's basic feature set.
Data:
1 | YAHOO.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:
1 | YAHOO.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 | ? |
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 0ms (+0) 4:55:00 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