index.mustache revision 9884e2fc45428bab51f805c6c3e03002728c1467
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney<div class="intro component">
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff The DataTable widget is responsible for rendering columnar data into a
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff highly customizable and fully accessible HTML table. The core
ea7c9c12989fa8a2b07209be8f4c89f5dbeb5b12Jeff Conniff functionality of DataTable is to visualize structured data as a table.
ea7c9c12989fa8a2b07209be8f4c89f5dbeb5b12Jeff Conniff A variety of Plugins can then be used to add features to the table such
ea7c9c12989fa8a2b07209be8f4c89f5dbeb5b12Jeff Conniff as sorting and scrolling.
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney{{>getting-started}}
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney<h2 id="using">Using DataTables</h2>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney<h3 id="basics">DataTable basics</h3>
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff A basic DataTable is comprised of columns and rows. Define the columns you
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff want to display in your DataTable with the <code>columnset</code>
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff attribute. Rows are created for you based on the data you define using the
9e916064638e1ec4de5d997bf484bb1138b5325eMatt Sweeney <code>recordset</code> attribute. Under the hood, the DataTable class uses
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney a Columnset instance and a Recordset instance to manage column and row data
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney<h3 id="columns">Working with columns</h3>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney A <code>columnset</code> can be defined with a simple array of
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <code>keys</code>. As long as these keys exist in your data, DataTable will
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff display these columns of data in the table. Note that your data may contain
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney other columns that are not displayed if they are not defined in the
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney <code>columnset</code> array. A Columnset will be created containing a
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney Column instance for each item in your array, with the <code>key</code>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney values you provided.
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney// Creates a Columnset with 3 Columns. "cost" is not rendered.
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeneyvar cols = ["id","name","price"];
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney// Columns must match data parameter names
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney {id:"ga-3475", name:"gadget", price:"$6.99", cost:"$5.99"},
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney {id:"sp-9980", name:"sprocket", price:"$3.75", cost:"$3.25"},
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney {id:"wi-0650", name:"widget", price:"$4.25", cost:"$3.75"}
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney// Creates a DataTable with 3 columns and 3 rows
57135c36536a2f81ce818f6a006f002261972244Jeff Conniffvar table = new Y.DataTable.Base({
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney columnset: cols,
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney recordset: data
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney}).render("#example");
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff For greater flexibility, the <code>columnset</code> array accepts
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff configuration objects as well as simple column name strings. When
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff identifying a column with a configuration object, use the <code>key</code>
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff property to reference the column name string. Below are a few other
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff available column configurations.
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff Use the <code>label</code> attribute to customize the rendered column
57135c36536a2f81ce818f6a006f002261972244Jeff Conniff// The label is the text that will be rendered in the table head
var table = new Y.DataTable.Base({
var table = new Y.DataTable.Base({
var table = new Y.DataTable.Base({
<td>Usually the value stored in the <code>Record</code> for the column. This is the default content that will be displayed.</td>
<td>The Array of IDs from all <code><th></code>s corresponding to the cell (mostly relevant to nested headers).</td>
var cost = o.record.getValue("cost"),
price = o.record.getValue("price");
var table = new Y.DataTable.Base({
{ key: "Rating.AverageRating", label: "Rating" }
var myDataSource = new Y.DataSource.Get({
source: "http://query.yahooapis.com/v1/public/yql?&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
resultListLocator: "query.results.Result",
resultFields: [ "Title", "Phone", "Rating.AverageRating" ]
var table = new Y.DataTable.Base({
table.render("#pizza");
request: "&q=select%20*%20from%20local.search%20where%20zip%3D%2794089%27%20and%20query%3D%27pizza%27"
request: "&q=select%20*%20from%20local.search%20where%20zip%3D%2794089%27%20and%20query%3D%27chinese%27"
{ key: "Rating.AverageRating", label: "Rating" }
var myDataSource = new Y.DataSource.Get({
source: "http://query.yahooapis.com/v1/public/yql?format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
.plug(Y.Plugin.DataSourceJSONSchema, {
resultListLocator: "query.results.Result",
resultFields: ["Title", "Phone", "Rating.AverageRating"]
.plug(Y.Plugin.DataSourceCache, {
var table = new Y.DataTable.Base({
.plug(Y.Plugin.DataTableDataSource, {
request: "&q=select%20*%20from%20local.search%20where%20zip%3D%2794089%27%20and%20query%3D%27chinese%27"
var myDataSource = new Y.DataSource.IO({
source: "/path/to/service.php?"
var table = new Y.DataTable.Base({
.plug(Y.Plugin.DataTableDataSource, {
myDataSource.setInterval(5000, {
var table = new Y.DataTable.Base({
plugins: [ Y.Plugin.DataTableSort ]
var table = new Y.DataTable.Base({
.plug(Y.Plugin.DataTableScroll, {