5
<title>Example: Basic DataTable</title>
6
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
<link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
<link rel="stylesheet" href="../assets/css/main.css">
9
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
<script src="../../build/yui/yui-min.js"></script>
15
<h1>Example: Basic DataTable</h1>
20
<div class="yui3-u-3-4">
22
<div class="content"><style scoped>
23
/* custom styles for this example */
24
.dt-example {margin:1em;}
26
/* css to counter global site css */
27
.dt-example th {text-transform:none;}
28
.dt-example table {width:auto;}
29
.dt-example caption {display:table-caption;}
33
border: 1px solid #eac9a9;
34
-moz-border-radius: 3px;
35
-webkit-border-radius: 3px;
38
-moz-box-shadow: 0 0 5px #ccc8b3;
39
-webkit-box-shadow: 0 0 5px #ccc8b3;
40
box-shadow: 0 0 5px #ccc8b3;
48
<strong>NOTICE</strong>: This example is for the <strong>deprecated
49
version of DataTable</strong>. The components referred to here will be
50
removed in future versions of YUI</strong>. If you are unable to
51
upgrade to <a href="../datatable/index.html">the latest DataTable
52
version</a> due to unresolvable feature conflicts from version 3.4.1 or
53
prior, please <a href="../../../projects/yui3/newticket/">file a
60
<p>The DataTable widget displays data in a tabular format. Use plugins and extensions to add features and functionality to the <code>Y.DataTable.Base</code> class.</p>
63
<div class="example yui3-skin-sam">
64
<div id="simple" class="yui3-skin-sam dt-example"></div>
66
<div id="labels" class="yui3-skin-sam dt-example"></div>
68
<script type="text/javascript">
69
YUI().use("datatable-base-deprecated", function (Y) {
70
var simpleCols = ["id","name","price"],
72
{id:"ga_3475", name:"gadget", price:"$6.99"},
73
{id:"sp_9980", name:"sprocket", price:"$3.75"},
74
{id:"wi_0650", name:"widget", price:"$4.25"}
77
{key:"mfr_parts_database_id", label:"Mfr Part ID", abbr:"ID"},
78
{key:"mfr_parts_database_name", label:"Mfr Part Name", abbr:"Name"},
79
{key:"mfr_parts_database_price", label:"Wholesale Price", abbr:"Price"}
82
{mfr_parts_database_id:"ga_3475", mfr_parts_database_name:"gadget", mfr_parts_database_price:"$6.99"},
83
{mfr_parts_database_id:"sp_9980", mfr_parts_database_name:"sprocket", mfr_parts_database_price:"$3.75"},
84
{mfr_parts_database_id:"wi_0650", mfr_parts_database_name:"widget", mfr_parts_database_price:"$4.25"}
87
dt1 = new Y.DataTable.Base({columnset:simpleCols, recordset:simpleData, summary:"Price sheet for inventory parts", caption:"Example table with simple columns"}).render("#simple"),
88
dt2 = new Y.DataTable.Base({columnset:labeledCols, recordset:labeledData, summary:"Price sheet for inventory parts", caption:"These columns have labels and abbrs"}).render("#labels");
94
<h2>Simple DataTable Use Cases</h2>
96
<pre class="code prettyprint"><div id="example" class="yui3-skin-sam"></div></pre>
100
<p>A basic table can be rendered into a given container by passing in a simple array of columns and an array of data objects into the constructor. As long as the columns map directly to the keys of the data objects, the table will be generated automatically from the data provided.</p>
102
<pre class="code prettyprint">YUI().use("datatable-base-deprecated", function(Y) {
103
var cols = ["id","name","price"],
105
{id:"ga-3475", name:"gadget", price:"$6.99"},
106
{id:"sp-9980", name:"sprocket", price:"$3.75"},
107
{id:"wi-0650", name:"widget", price:"$4.25"}
109
dt = new Y.DataTable.Base({
112
summary: "Price sheet for inventory parts",
113
caption: "Example table with simple columns"
114
}).render("#example");
118
<p>Your column definitions may be an array of object literals in order to support any number of configurations that are supported by the <code>Y.Column</code> class. For instance, you may wish to define a <code>label</code> that will be displayed in each column header. Use the <code>key</code> property to define where data for the column will be coming from.</p>
120
<pre class="code prettyprint">YUI().use("datatable-base-deprecated", function(Y) {
122
{ key: "mfr_parts_database_id", label: "Mfr Part ID", abbr: "ID"},
123
{ key: "mfr_parts_database_name", label: "Mfr Part Name", abbr: "Name"},
124
{ key: "mfr_parts_database_price", label: "Wholesale Price", abbr: "Price"}
127
{ mfr_parts_database_id: "ga_3475", mfr_parts_database_name: "gadget", mfr_parts_database_price: "$6.99"},
128
{ mfr_parts_database_id: "sp_9980", mfr_parts_database_name: "sprocket", mfr_parts_database_price: "$3.75"},
129
{ mfr_parts_database_id: "wi_0650", mfr_parts_database_name: "widget", mfr_parts_database_price: "$4.25"}
131
dt = new Y.DataTable.Base({
134
summary: "Price sheet for inventory parts",
135
caption: "These columns have labels and abbrs"
136
}).render("#example");
143
<div class="yui3-u-1-4">
144
<div class="sidebar">
148
<div class="sidebox">
150
<h2 class="no-toc">Examples</h2>
154
<ul class="examples">
157
<li data-description="This example illustrates simple DataTable use cases.">
158
<a href="datatable-basic.html">Basic DataTable</a>
163
<li data-description="DataTable loaded with JSON data from a remote webservice via DataSource.Get">
164
<a href="datatable-dsget.html">DataTable + DataSource.Get + JSON Data</a>
169
<li data-description="DataTable loaded with XML data from a remote webservice via DataSource.IO.">
170
<a href="datatable-dsio.html">DataTable + DataSource.IO + XML Data</a>
175
<li data-description="Custom format data for display.">
176
<a href="datatable-formatting.html">Formatting Row Data for Display</a>
181
<li data-description="DataTable with nested column headers.">
182
<a href="datatable-nestedcols.html">Nested Column Headers</a>
187
<li data-description="DataTable with column sorting.">
188
<a href="datatable-sort.html">Column Sorting</a>
193
<li data-description="DataTable with vertical and/or horizontal scrolling rows.">
194
<a href="datatable-scroll.html">Scrolling DataTable</a>
209
<script src="../assets/vendor/prettify/prettify-min.js"></script>
210
<script>prettyPrint();</script>