migration.mustache revision e8d16592842bdb884e0e4d938f334b6ac5b7cad0
199767f8919635c4928607450d9e0abb932109ceToomas Soome.yui3-skin-sam table {
199767f8919635c4928607450d9e0abb932109ceToomas Soome width: auto;
199767f8919635c4928607450d9e0abb932109ceToomas Soome.yui3-skin-sam td,
199767f8919635c4928607450d9e0abb932109ceToomas Soome.yui3-skin-sam th {
199767f8919635c4928607450d9e0abb932109ceToomas Soome border: 0 none;
199767f8919635c4928607450d9e0abb932109ceToomas Soome.before, .after {
199767f8919635c4928607450d9e0abb932109ceToomas Soome margin-left: 5%;
199767f8919635c4928607450d9e0abb932109ceToomas Soome color: #b00;
199767f8919635c4928607450d9e0abb932109ceToomas Soome<div class="intro">
199767f8919635c4928607450d9e0abb932109ceToomas Soome In version 3.5.0, DataTable and supporting modules underwent a major
199767f8919635c4928607450d9e0abb932109ceToomas Soome refactoring. The new architecture <strong>does not support full backward
199767f8919635c4928607450d9e0abb932109ceToomas Soome compatibility</strong> with versions 3.4.1 and prior. This guide should
199767f8919635c4928607450d9e0abb932109ceToomas Soome help answer questions that may come up when upgrading to the lastest
199767f8919635c4928607450d9e0abb932109ceToomas Soome<h2 id="overview">Overview of API changes from 3.4.1</h2>
199767f8919635c4928607450d9e0abb932109ceToomas Soome The architectural change resulted in the deprecation, replacement, or
199767f8919635c4928607450d9e0abb932109ceToomas Soome removal of nearly all attributes and properties from the version 3.4.1
199767f8919635c4928607450d9e0abb932109ceToomas Soome implementation. We'll go into details below, but here are the high points:
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`Y.DataTable` is now the preferred class for instantiation.</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>The `recordset` attribute is deprecated. Use `data`.</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>The `columnset` attribute is deprecated. Use `columns`.</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome Cell formatters have changed a little, template attributes and
199767f8919635c4928607450d9e0abb932109ceToomas Soome properties a lot.
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>Table markup has changed.</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>Table sorting is now via configuration, not plugin.</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>Table scrolling is now via configuration, not plugin.</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome<h2 id="before-after">A Quick Before-And-After</h2>
199767f8919635c4928607450d9e0abb932109ceToomas Soome Unless you were really digging into the guts of DataTable, just changing
199767f8919635c4928607450d9e0abb932109ceToomas Soome `DataTable.Base` to `DataTable`, `columnset` to `columns`, and `recordset`
199767f8919635c4928607450d9e0abb932109ceToomas Soome to `data` should get you most of the way there.
199767f8919635c4928607450d9e0abb932109ceToomas Soome<h3 id="quick-basic">Basic Table</h3>
199767f8919635c4928607450d9e0abb932109ceToomas Soome<div class="demo yui3-skin-sam">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <div id="basic-demo"></div>
199767f8919635c4928607450d9e0abb932109ceToomas SoomeYUI().use('datatable', function (Y) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome columns: ["id", "name", "price"],
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 1, name: "Bread", price: 3.45 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 2, name: "Milk", price: 4.99 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 3, name: "Eggs", price: 2.75 }
199767f8919635c4928607450d9e0abb932109ceToomas Soome caption: "Price List"
199767f8919635c4928607450d9e0abb932109ceToomas Soome }).render('#basic-demo');
199767f8919635c4928607450d9e0abb932109ceToomas Soome<div class="yui3-g">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <div class="yui3-u before">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <h4>Before</h4>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`columnset`</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`recordset`</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soomevar table = new Y.DataTable.Base({
199767f8919635c4928607450d9e0abb932109ceToomas Soome columnset: ["id", "name", "price"],
199767f8919635c4928607450d9e0abb932109ceToomas Soome recordset: [
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 1, name: "Bread", price: 3.45 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 2, name: "Milk", price: 4.99 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 3, name: "Eggs", price: 2.75 }
199767f8919635c4928607450d9e0abb932109ceToomas Soome caption: "Price List"
199767f8919635c4928607450d9e0abb932109ceToomas Soome}).render('#basic-demo');
199767f8919635c4928607450d9e0abb932109ceToomas Soome <div class="yui3-u after">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <h4>After</h4>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`columns`</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`data`</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soomevar table = new Y.DataTable({
199767f8919635c4928607450d9e0abb932109ceToomas Soome columns: ["id", "name", "price"],
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 1, name: "Bread", price: 3.45 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 2, name: "Milk", price: 4.99 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 3, name: "Eggs", price: 2.75 }
199767f8919635c4928607450d9e0abb932109ceToomas Soome caption: "Price List"
199767f8919635c4928607450d9e0abb932109ceToomas Soome}).render('#basic-demo');
199767f8919635c4928607450d9e0abb932109ceToomas Soome<h3 id="quick-remote">Table With Remote Data</h3>
199767f8919635c4928607450d9e0abb932109ceToomas Soome<div class="demo yui3-skin-sam">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <div id="remote-demo"></div>
199767f8919635c4928607450d9e0abb932109ceToomas SoomeYUI().use('datatable', 'datatable-datasource', function (Y) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome var table = new Y.DataTable({
199767f8919635c4928607450d9e0abb932109ceToomas Soome columns: ["id", "name", "price"],
199767f8919635c4928607450d9e0abb932109ceToomas Soome caption: "Price List"
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Just pretend this is remote. It works the same anyway
199767f8919635c4928607450d9e0abb932109ceToomas Soome var source = new Y.DataSource.Local({
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 1, name: "Bread", price: 3.45 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 2, name: "Milk", price: 4.99 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 3, name: "Eggs", price: 2.75 }
199767f8919635c4928607450d9e0abb932109ceToomas Soome // (optional) Add DataSource plugins
199767f8919635c4928607450d9e0abb932109ceToomas Soome datasource: source
199767f8919635c4928607450d9e0abb932109ceToomas Soome table.render('#remote-demo');
199767f8919635c4928607450d9e0abb932109ceToomas Soome<div class="yui3-g">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <div class="yui3-u before">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <h4>Before</h4>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`columnset`</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`recordset`</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soomevar table = new Y.DataTable.Base({
199767f8919635c4928607450d9e0abb932109ceToomas Soome columnset: ["id", "name", "price"],
199767f8919635c4928607450d9e0abb932109ceToomas Soome caption: "Price List"
199767f8919635c4928607450d9e0abb932109ceToomas Soomevar source = new Y.DataSource.IO({
199767f8919635c4928607450d9e0abb932109ceToomas Soome}).plug(Y.Plugin.DataSourceJSONSchema, { ... });
199767f8919635c4928607450d9e0abb932109ceToomas Soome datasource: source
199767f8919635c4928607450d9e0abb932109ceToomas Soometable.render('#remote-demo');
199767f8919635c4928607450d9e0abb932109ceToomas Soome <div class="yui3-u after">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <h4>After</h4>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`columns`</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`data`</li>
199767f8919635c4928607450d9e0abb932109ceToomas SoomeYUI().use('datatable', 'datatable-datasource', function (Y) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome var table = new Y.DataTable({
199767f8919635c4928607450d9e0abb932109ceToomas Soome columns: ["id", "name", "price"],
199767f8919635c4928607450d9e0abb932109ceToomas Soome caption: "Price List"
199767f8919635c4928607450d9e0abb932109ceToomas Soome // Everything else is the same as before...
199767f8919635c4928607450d9e0abb932109ceToomas Soome<h3 id="quick-formatter">Formatted Columns</h3>
199767f8919635c4928607450d9e0abb932109ceToomas Soome<div class="demo yui3-skin-sam">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <div id="formatter-demo"></div>
199767f8919635c4928607450d9e0abb932109ceToomas SoomeYUI().use('datatable', function (Y) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome { key: "price", formatter: "${value}" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { key: "price",
199767f8919635c4928607450d9e0abb932109ceToomas Soome formatter: function (o) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return '$' + o.value.toFixed(2);
199767f8919635c4928607450d9e0abb932109ceToomas Soome { key: "price",
199767f8919635c4928607450d9e0abb932109ceToomas Soome nodeFormatter: function (o) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return false;
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 1, name: "Bread", price: 3.45 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 2, name: "Milk", price: 4.99 },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { id: 3, name: "Eggs", price: 2.75 }
199767f8919635c4928607450d9e0abb932109ceToomas Soome caption: "Price List"
199767f8919635c4928607450d9e0abb932109ceToomas Soome }).render('#formatter-demo');
199767f8919635c4928607450d9e0abb932109ceToomas Soome<div class="yui3-g">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <div class="yui3-u before">
199767f8919635c4928607450d9e0abb932109ceToomas Soome <h4>Before</h4>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`formatter: "\\${value}"`</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soome <li>`formatter`</li>
199767f8919635c4928607450d9e0abb932109ceToomas Soomevar table = new Y.DataTable.Base({
199767f8919635c4928607450d9e0abb932109ceToomas Soome columnset: [
199767f8919635c4928607450d9e0abb932109ceToomas Soome { key: "price", formatter: "\\${value}" },
199767f8919635c4928607450d9e0abb932109ceToomas Soome { key: "price",
199767f8919635c4928607450d9e0abb932109ceToomas Soome formatter: function (o) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return '$' + o.value.toFixed(2);
var cell = this.createCell(o);
if (o.value > 4) {
cell.addClass('spendy');
<li>`o.className`</li>
<li>`o.cell`</li>
var table = new Y.DataTable({
if (o.value > 4) {
o.className += "spendy";
return '$' + o.value.toFixed(2);
if (o.value > 4) {
o.cell.addClass('spendy');
var table = new Y.DataTable({
table.render('#sort-demo');
<li>`plug(Y.Plugin.DataTableSort)`</li>
var table = new Y.DataTable.Base({
table.render('#sort-demo');
<li><del>`plug(Y.Plugin.DataTableSort)`</del></li>
var table = new Y.DataTable({
var table = new Y.DataTable({
var table = new Y.DataTable({
table.render('#sort-demo');
var table = new Y.DataTable({
<li>`plug(Y.Plugin.DataTableScroll, ...)`</li>
var table = new Y.DataTable.Base({
table.render('#scroll-demo');
<li><del>`plug(Y.Plugin.DataTableScroll, ...)`</del></li>
var table = new Y.DataTable({
<h3 id="quick-mutable">Adding/Removing/Modifying Table Rows</h3>
var table = new Y.DataTable({
table.addRow({ id: 4, name: "Cheese", price: 24.97 });
table.modifyRow(1, { name: "Artisan bread" });
table.removeRow(2);
<li>`Y.DataTable.Base`</li>
var table = new Y.DataTable.Base({
<li>`Y.DataTable`</li>
var table = new Y.DataTable({
`Y.DataTable.Base` should only be used as a base class for creating custom
future versions. <strong>`table.get("columnset")` will not return a
`Y.Columnset` instance</strong>.
future versions. <strong>`table.get("recordset")` will return a
templates, such as `Y.DataTable.BodyView.prototype.CELL_TEMPLATE` or
<a href="index.html#formatters">Formatting Cell Data</a> for details.
`Y.Plugin.DataTableSort` has been deprecated. Sorting can be
<a href="#sort">enabled by attribute configuration</a> on `Y.DataTable`
`Y.Plugin.DataTableScroll` has been deprecated. Scrolling can be