index.mustache revision e8d16592842bdb884e0e4d938f334b6ac5b7cad0
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt<style type="text/css">
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt .yui3-datatable table {
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews width: auto;
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews .yui3-datatable td, .yui3-datatable th {
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews border: 0 none;
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt<div class="intro component">
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt The DataTable widget is responsible for rendering columnar data into a
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt highly customizable and fully accessible HTML table. The core
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt functionality of DataTable is to visualize structured data as a table.
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt A variety of class extensions can then be used to add features to the
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt table such as sorting and scrolling.
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt{{>getting-started}}
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt<div class="callout">
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt <h2 id="migration-intro">Upgrading from version 3.4.1 or older?</h2>
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt <strong>NOTE: As of version 3.5.0, DataTable and supporting module APIs
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt have been changed in backward incompatible ways.</strong>
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt If you are currently using DataTable version 3.4.1 or prior, please
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt read the <a href="migration.html">3.5.0+ Migration Guide</a> for tips
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt to avoid unpleasant surprises when you upgrade.
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt<h2 id="using">DataTable Basics</h2>
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt A basic DataTable is comprised of columns and rows. Define the columns you
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt want to display in your DataTable with the `columns` attribute. Rows are
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt created for you based on the data you provide to the `data` attribute.
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt Under the hood, the DataTable class uses a ModelList instance to manage the
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt row data properties.
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt// Columns must match data object property names
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt { id: "ga-3475", name: "gadget", price: "$6.99", cost: "$5.99" },
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt { id: "sp-9980", name: "sprocket", price: "$3.75", cost: "$3.25" },
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt { id: "wi-0650", name: "widget", price: "$4.25", cost: "$3.75" }
1479200aa05414b2acf33607dbd1682c16f58c51Evan Huntvar table = new Y.DataTable({
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt columns: ["id", "name", "price"],
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt // Optionally configure your table with a caption
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt caption: "My first DataTable!",
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt // and/or a summary (table attribute)
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt summary: "Example DataTable showing basic instantiation configuration"
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt<p>This code produces this table:</p>
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt<div id="example1" class="yui3-skin-sam"></div>
1479200aa05414b2acf33607dbd1682c16f58c51Evan HuntYUI().use('datatable-base', function (Y) {
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt // Columns must match data object property names
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt var data = [
1479200aa05414b2acf33607dbd1682c16f58c51Evan Hunt { id: "ga-3475", name: "gadget", price: "$6.99", cost: "$5.99" },
var table = new Y.DataTable({
table.render("#example1");
var table = new Y.DataTable({
table.render('#example2');
{ "mfr-parts-database-id": "ga-3475", "mfr-parts-database-name": "gadget", "mfr-parts-database-price": "$6.99", cost: "$5.99" },
{ "mfr-parts-database-id": "sp-9980", "mfr-parts-database-name": "sprocket", "mfr-parts-database-price": "$3.75", cost: "$3.25" },
{ "mfr-parts-database-id": "wi-0650", "mfr-parts-database-name": "widget", "mfr-parts-database-price": "", cost: "$3.75" },
{ "mfr-parts-database-id": "nu-0001", "mfr-parts-database-name": "nut", "mfr-parts-database-price": "$0.25", cost: "$3.75" }
var table = new Y.DataTable({
table.render("#example2");
var table = new Y.DataTable({
var table = new Y.DataTable({
if (o.value > 3) {
o.className += ' yellow-background';
o.value *= 0.75;
if (o.value > 4) {
o.cell.ancestor().addClass('red-text');
o.value *= 0.75;
o.cell.setContent(content);
if (o.value > 3) {
o.className += ' yellow-background';
o.value *= 0.75;
if (o.value > 4) {
o.cell.ancestor().addClass('red-text');
o.value *= 0.75;
o.cell.setContent(content);
var table = new Y.DataTable({
content string from the function. Alternately, just update `o.value` with
updating `o.value` <em>do not include a return statement</em>.
prefix : o.column.currencySymbol || '$',
decimalPlaces : o.column.decimalPlaces || 2,
decimalSeparator : o.column.decimalSeparator || '.',
thousandsSeparator: o.column.thousandsSeparator || ','
logic by leave `o.value` unchanged, `nodeFormatters` must assign content to
<a href="http://yuilibrary.com/yui/docs/event/delegation.html">delegated</a>
<a href="http://yuilibrary.com/yui/docs/api/classes/DataTable.html#method_delegate">`delegate()` method</a>.
altered) `o.value` property is tested for `undefined` or the empty string.
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",
locator: "Rating.AverageRating"
var table = new Y.DataTable({
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({
.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({
.plug(Y.Plugin.DataTableDataSource, {
myDataSource.setInterval(5000, {
var table = new Y.DataTable({
var table = new Y.DataTable({
<a href="http://yuilibrary.com/projects/yui3/ticket/2529761">not
<a href="http://yuilibrary.com/projects/yui3/ticket/2531047">not appear