src/cm/media/js/lib/yui/yui_3.10.3/docs/datatable/migration.html
author Yves-Marie Haussonne <ymh.work+github@gmail.com>
Fri, 09 May 2014 18:35:26 +0200
changeset 656 a84519031134
parent 525 89ef5ed3c48b
permissions -rw-r--r--
add link to "privacy policy" in the header test

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>3.5.0+ Migration Guide</title>
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
    <link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
    <script src="../../build/yui/yui-min.js"></script>
    
</head>
<body>
<!--
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
-->
<div id="doc">
    <div id="hd">
        <h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
    </div>
    
        <a href="#toc" class="jump">Jump to Table of Contents</a>
    

            <h1>3.5.0+ Migration Guide</h1>
    <div class="yui3-g">
        <div class="yui3-u-3-4">
            <div id="main">
                <div class="content"><style>
#docs-main li {
    margin: 1ex 0;
}

li code,
td code {
    white-space: nowrap;
    background: #fcfbfa;
    border: 1px solid #d0d5ec;
    padding: 0 3px;
}
li code {
    border-color: #efeeed;
}
.yui3-skin-sam table {
    width: auto;
}
.yui3-skin-sam td,
.yui3-skin-sam th {
    border: 0 none;
}

.demo    { width: 40%; }
.details { width: 60%; }
.before, .after { width: 47%; }
.after {
    margin-left: 5%;
}

#quickref code em {
    color: #900;
}
#quickref code strong {
    color: #090;
}
#quickref pre.code {
    margin-top: 0;
    margin-bottom: 0;
}

.spendy {
    color: #b00;
}
</style>
<div class="intro">
    <p>
        DataTable and supporting modules were rebuilt in version 3.5.0.  The
        new architecture is <strong>not fully backward compatible</strong> with
        versions 3.4.1 and prior.  This guide is to help answer questions that
        may come up when upgrading to the latest version.
    </p>

    <p>
        This guide focuses on 3.4.1 API compatibility.  It <strong>does not
        describe new features added in 3.5.0</strong> (there were a lot).
        Refer to the updated <a href="index.html">DataTable user guide</a> for
        that.
    </p>

    <p>
        If you are unable to upgrade due to unresolvable issues, you can use the
        <a href="../datatable-deprecated/index.html"><code>datatable-deprecated</code></a>
        module suite, which is equivalent to the 3.4.1 implementation.  But be
        aware that these modules will be removed in a future version of YUI.
    </p>
</div>

<h2 id="overview">Overview of API changes from 3.4.1</h2>

<p>
    The architectural change resulted in the deprecation, replacement, or
    removal of nearly all attributes and properties from the version 3.4.1
    implementation.  Here is a quick list of the changes most likely to affect
    your upgrade:
</p>

<ol id="quickref">
    <li>
        <code>new <em>Y.DataTable.Base</em>(...)</code> &rarr;
        <code>new <strong>Y.DataTable</strong>({ ... })</code>
    </li>
    <li>
        <div class="yui3-g">
        <div class="yui3-u">
<pre class="code prettyprint">new Y.DataTable.Base({
    columnset: [ ... ],
    recordset: [ ... ]
});</pre>

        </div>
        <p class="yui3-u" style="line-height: 72px; margin: 0 1em;">&rarr;</p>
        <div class="yui3-u">
<pre class="code prettyprint">new Y.DataTable({
    columns: [ ... ],
    data   : [ ... ]
});</pre>

        </div>
        </div>
    </li>
    <li>
        (cells rendered as HTML by default) &rarr;
        <code>columns: [ { key: 'email', <strong>allowHTML: true</strong> }, ... ]</code>
    </li>
    <li>
        <code>table.plug(<em>Y.Plugin.DataTableSort</em>)</code> &rarr; <em>(plugin not needed)</em>
        <a href="#features">See below</a> or read
        <a href="index.html#sorting">the user guide</a>
    </li>
    <li>
        <code>table.plug(<em>Y.Plugin.DataTableScroll</em>, ...)</code> &rarr;
        <em>(plugin not needed)</em>
        <a href="#features">See below</a> or read
        <a href="index.html#scrolling">the user guide</a>
    </li>
    <li>
        <code>columnset: [ { <em>formatter: function (o) { ... }</em> } ]</code>
        &rarr;
        (formatter changes)
        <a href="#formatters">See below</a> or read
        <a href="index.html#scrolling">the user guide</a>
    </li>
    <li>
        <code>record.<em>getValue(fieldName)</em></code> &rarr;
        <code>record.<strong>get(fieldName)</strong></code>
    </li>
</ol>

<h2 id="instantiation">Instantiation and Instance Configuration Changes</h2>

<p>
    As of 3.5.0, <code>Y.DataTable</code> is no longer just a namespace, but is now the
    preferred constructor for DataTable instances.
</p>

<pre class="code prettyprint">var table = new Y.DataTable({
    &#x2F;&#x2F; Column configuration looks much the same except the attribute name
    columns: [
        { key: &#x27;name&#x27;, label: &#x27;Name&#x27;, sortable: true, width: &#x27;200px&#x27; },
        {
            key: &#x27;birthdate&#x27;,
            label: &#x27;Age&#x27;,
            sortable: true,
            formatter: function (o) {
                var now = new Date(),
                    years = now.getYear() - o.value.getYear();

                now.setYear(o.value.getYear());

                return years - (o.value &lt; now);
            }
        }
    ],
    &#x2F;&#x2F; Passing in row data looks much the same except the attribute name
    data: [
        { name: &#x27;Tom Brokaw&#x27;,     birthdate: new Date(1940, 1, 6) },
        { name: &#x27;Peter Jennings&#x27;, birthdate: new Date(1938, 6, 29) },
        { name: &#x27;Katie Couric&#x27;,   birthdate: new Date(1957, 1, 7) },
        { name: &#x27;Brian Williams&#x27;, birthdate: new Date(1958, 4, 5) },
        { name: &#x27;Matt Lauer&#x27;,     birthdate: new Date(1957, 11, 30) }
    ]
}).render(&#x27;#over-there&#x27;);</pre>


<p>
    The <code>Y.DataTable.Base</code> class still exists, but is useful primarily as a
    superclass for extension.  The attributes of <code>Y.DataTable.Base</code> are the
    same as those of <code>Y.DataTable</code>, less any attributes added by class
    extensions (<a href="#features">see below</a>).
</p>

<p>
    Configuration attributes that have changed from 3.4.1 are:
</p>

<table>
<thead>
    <tr>
        <th>Attribute</th>
        <th>Change</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td><code>columnset</code></td>
        <td>
            <strong>Deprecated</strong>.  Use <code>columns</code>.  <code>columnset</code> will
            behave as an alias for <code>columns</code> for a short time, but will be
            removed in future versions. <a href="#columns">See below</a>.
        </td>
    </tr>
    <tr>
        <td><code>recordset</code></td>
        <td>
            <strong>Deprecated</strong>.  Use <code>data</code>.  <code>recordset</code> will
            behave as an alias for <code>data</code> for a short time, but will be
            removed in future versions. <a href="#data">See below</a>.
        </td>
    </tr>
    <tr>
        <td><code>tdValueTemplate</code></td>
        <td>
            <strong>Removed</strong>. Use column <code>formatter</code>, <code>cellTemplate</code>,
            or override the <code>Y.DataTable.BodyView</code> instance's <code>CELL_TEMPLATE</code>.
        </td>
    </tr>
    <tr>
        <td><code>thValueTemplate</code></td>
        <td>
            <strong>Removed</strong>. Use column <code>label</code>, <code>headerTemplate</code>,
            or override the <code>Y.DataTable.HeaderView</code> instance's <code>CELL_TEMPLATE</code>.
        </td>
    </tr>
    <tr>
        <td><code>trTemplate</code></td>
        <td>
            <strong>Removed</strong>. Use column <code>nodeFormatter</code> or override
            the <code>Y.DataTable.BodyView</code> instance's <code>ROW_TEMPLATE</code>.
        </td>
    </tr>
</tbody>
</table>

<h2 id="formatters">Table and Cell Formatting Changes</h2>

<p>
    The following changes apply to table and column cell formatting:
</p>

<ul>
    <li>
        If cell values include HTML, add <code>allowHTML: true</code> to the column
        configuration.  HTML is escaped by default for security.
    </li>
    <li>
        <code>o.classnames</code> in the formatter parameter is now <code>o.className</code>.
    </li>
    <li>
        <code>o.column</code> in the formatter parameter is now <a href="#columns">the
        plain JavaScript object</a> containing the column configurations rather
        than a <code>Y.Column</code> instance.
    </li>
    <li>
        <code>o.record</code> in the formatter parameter is now <a href="#data">a Model
        instance</a> instead of a <code>Y.Record</code> instance.
    </li>
    <li>
        <code>this.createCell(o)</code>, <code>o.td</code>, <code>o.tr</code>, and <code>o.tbody</code> no longer exist on
        the parameter passed to <code>formatter</code> functions.  Use
        <a href="index.html#nodeformatter"><code>nodeFormatter</code></a>s.
    </li>
    <li>
        <code>o.headers</code> is now at <code>o.column._headers</code>, but is read-only for
        <code>formatter</code> functions.  If you need to change the cell's headers
        attribute, add a {placeholder} for them to a custom <code>cellTemplate</code> for
        the column, or use a <code>nodeFormatter</code>.
    </li>
    <li>
        The table's <code>tdValueTemplate</code>, <code>thValueTemplate</code>, and <code>trTemplate</code> no
        longer exist, nor do the DataTable instance properties <code>tdTemplate</code> and
        <code>thTemplate</code>.  Use <code>formatter</code> strings or functions to customize the
        content of data cells in a column and <code>label</code> strings to customize the
        content of header cells.  To modify the <code>&lt;td&gt;</code> or <code>&lt;th&gt;</code> entirely, set
        the column configuration <code>cellTemplate</code> or <code>headerTemplate</code>.
    </li>
</ul>

<div class="yui3-g">
    <div class="yui3-u before">
        <h4 class="no-toc">3.4.1</h4>

<pre class="code prettyprint">var table = new Y.DataTable.Base({
    columnset: [
        { key: &quot;id&quot;,
          emptyCellValue: &quot;&lt;em&gt;new&lt;&#x2F;em&gt;&quot; },
        { key: &quot;name&quot; },
        { key: &quot;price&quot;, formatter: &quot;${value}&quot; },
        { key: &quot;price&quot;,
          formatter: function (o) {
            if (o.value &gt; 4) {
                o.classnames += &quot;spendy&quot;;
            }
            return &#x27;$&#x27; + o.value.toFixed(2);
          }
        },
        { key: &quot;price&quot;,
          formatter: function (o) {
            var cell = this.createCell(o);

            if (o.value &gt; 4) {
                cell.addClass(&#x27;spendy&#x27;);
            }

            cell.setHTML(&#x27;$&#x27; + o.value);
          }
        }
    ],
    data: [
        { id: 1, name: &quot;Bread&quot;, price: 3.45 },
        { id: 2, name: &quot;Milk&quot;,  price: 4.99 },
        { id: 3, name: &quot;Eggs&quot;,  price: 2.75 }
    ]
}).render(&quot;#over-there&quot;);</pre>

    </div>
    <div class="yui3-u after">
        <h4 class="no-toc">3.5.0</h4>

<pre class="code prettyprint">var table = new Y.DataTable({
    columns: [
        { key: &quot;id&quot;,
          emptyCellValue: &quot;&lt;em&gt;new&lt;&#x2F;em&gt;&quot;,
          allowHTML: true },
        { key: &quot;name&quot; },
        { key: &quot;price&quot;, formatter: &quot;${value}&quot; },
        { key: &quot;price&quot;,
          formatter: function (o) {
            if (o.value &gt; 4) {
                o.className += &quot;spendy&quot;;
            }
            return &#x27;$&#x27; + o.value.toFixed(2);
          }
        },
        { key: &quot;price&quot;,
          nodeFormatter: function (o) {
            if (o.value &gt; 4) {
                o.cell.addClass(&#x27;spendy&#x27;);
            }

            o.cell.setHTML(&#x27;$&#x27; + o.value);

            return false;
          }
        }
    ],
    data: [
        { id: 1, name: &quot;Bread&quot;, price: 3.45 },
        { id: 2, name: &quot;Milk&quot;,  price: 4.99 },
        { id: 3, name: &quot;Eggs&quot;,  price: 2.75 }
    ]
}).render(&quot;#over-there&quot;);</pre>

    </div>
</div>

<p>
    Read the <a href="index.html#formatters">Formatting Cell Data</a> section in
    the DataTable user guide for more details.
</p>

<h2 id="columns">Column Configuration Changes</h2>

<p>
    As of 3.5.0, the <code>Y.Columnset</code> and <code>Y.Column</code> classes have been deprecated.
    The DataTable configuration attribute <code>columnset</code> has been deprecated in
    favor of the <code>columns</code> attribute.  The <code>columnset</code> attribute has been
    retained for <em>partial</em> backward compatibility.  Columns are now
    stored as an array of simple JavaScript objects rather than class instances.
</p>

<pre class="code prettyprint">var table = new Y.DataTable({
    columnset: [ &#x27;name&#x27;, &#x27;age&#x27; ],
    ...
});

&#x2F;&#x2F; columnset passes through to columns
var columns = table.get(&#x27;columns&#x27;); &#x2F;&#x2F; =&gt; Array, not Columnset instance

table.set(&#x27;columnset&#x27;, [ ... (new column configurations) ... ]);

&#x2F;&#x2F; backward compatibility stops here
var columnset = table.get(&#x27;columnset&#x27;); &#x2F;&#x2F; =&gt; Array, not Columnset instance</pre>


<p>
    Strings passed into the column configuration will become objects with those
    strings as the value of the <code>key</code> property.
</p>

<p>
    See the <a href="index.html#columns">Column configuration</a> section in
    the user guide for more details.
</p>

<h2 id="data">Row Data Configuration Changes</h2>

<p>
    As of 3.5.0, DataTable uses <code>Y.Model</code> and <code>Y.ModelList</code> to store row data.
    <code>Y.Recordset</code> and <code>Y.Record</code> haven't been deprecated, but may be in the
    future.  The <code>recordset</code> attribute has been retained for <em>partial</em>
    backward compatibility.  The <code>data</code> ModelList can be assigned to, but
    retrieving the value of the attribute will return the ModelList, <em>not
    a <code>Y.Recordset</code> instance</em>.
</p>

<pre class="code prettyprint">var table = new Y.DataTable({
    columnset: [ ... ],
    recordset: [
        { name: &#x27;Tom Brokaw&#x27;,     birthdate: new Date(1940, 1, 6) },
        { name: &#x27;Peter Jennings&#x27;, birthdate: new Date(1938, 6, 29) },
        { name: &#x27;Katie Couric&#x27;,   birthdate: new Date(1957, 1, 7) },
        ...
    ]
});

&#x2F;&#x2F; recordset passes through to data.
var data = table.get(&#x27;data&#x27;); &#x2F;&#x2F; =&gt; ModelList instance

table.set(&#x27;recordset&#x27;, [ ... (new data records) ... ]);

&#x2F;&#x2F; backward compatibility stops here
var recordset = table.get(&#x27;recordset&#x27;); &#x2F;&#x2F; =&gt; ModelList, not Recordset</pre>


<p>
    <code>Y.Record</code> stores all values in a single attribute named <code>data</code>, where <code>Y.Model</code> uses individual attributes for each value.
</p>

<div class="yui3-g">
    <div class="yui3-u before">
        <h4 class="no-toc">3.4.1</h4>

<pre class="code prettyprint">&#x2F;&#x2F; Y.Record
var record = oldTable.get(&#x27;recordset&#x27;).item(0);

record.getValue(&#x27;birthdate&#x27;); &#x2F;&#x2F; =&gt; Date(1940, 1, 6)
record.get(&#x27;data&#x27;).birthdate; &#x2F;&#x2F; =&gt; same</pre>

    </div>
    <div class="yui3-u after">
        <h4 class="no-toc">3.5.0</h4>
<pre class="code prettyprint">&#x2F;&#x2F; Y.Model
var model = newTable.getRecord(0);

model.get(&#x27;birthdate&#x27;); &#x2F;&#x2F; =&gt; Date(1940, 1, 6)</pre>

    </div>
</div>

<p>
    <strong>This change breaks column/record keys that contain periods</strong>.
    Attribute treats periods as subproperty indicators, so periods are no
    longer allowed;  use an alternate character.  In the case of remote data
    that is parsed by <code>Y.Plugin.DataSourceJSONSchema</code>, use the <code>locator</code>
    configuration for fields to extract subproperty values.  A benefit to doing
    this is that you may not need to specify a column <code>label</code>.
</p>

<div class="yui3-g">
    <div class="yui3-u before">
        <h4 class="no-toc">3.4.1</h4>

<pre class="code prettyprint">var table = new Y.DataTable.Base({
    columnset: [
        { key: &quot;id&quot; },
        { key: &quot;Product.Name&quot;,  label: &quot;Product&quot; },
        { key: &quot;Product.Price&quot;, label: &quot;Price&quot; }
    ],
    caption: &quot;Price List&quot;
}).plug(Y.Plugin.DataTableDataSource, {
    datasource: new Y.DataSource.IO({
        source: &quot;&#x2F;service&#x2F;price-list&quot;
    }).plug(Y.Plugin.DataSourceJSONSchema, {
        schema: {
            resultListLocator: &quot;items&quot;,
            resultFields: [
                { key: &quot;id&quot; },
                { key: &quot;Product.Name&quot; },
                { key: &quot;Product.Price&quot; }
            ]
        }
    })
});

table.datasource.load(...);</pre>

    </div>
    <div class="yui3-u after">
        <h4 class="no-toc">3.5.0</h4>

<pre class="code prettyprint">var table = new Y.DataTable({
    columns: [ &quot;id&quot;, &quot;Product&quot;, &quot;Price&quot; ],
    caption: &quot;Price List&quot;
}).plug(Y.Plugin.DataTableDataSource, {
    datasource: new Y.DataSource.IO({
        source: &quot;&#x2F;service&#x2F;price-list&quot;
    }).plug(Y.Plugin.DataSourceJSONSchema, {
        schema: {
            resultListLocator: &quot;items&quot;,
            resultFields: [
                { key: &quot;id&quot; },
                { key: &quot;Product&quot;,
                  locator: &quot;Product.Name&quot; },
                { key: &quot;Price&quot;,
                  locator: &quot;Product.Price&quot; }
            ]
        }
    })
});

table.datasource.load(...);</pre>

    </div>
</div>

<p>
    If you are using any Recordset plugins, your code will need to be modified.
    Some loss of functionality may result.
</p>

<dl>
    <dt><code>Y.Plugin.RecordsetSort</code></dt>
    <dd>
        This plugin was formerly applied by the <code>Y.Plugin.DataTableSort</code> plugin
        to the DataTable's Recordset instance.  Sorting is now enabled
        <a href="#features">through a class extension</a>.
    </dd>

    <dt><code>Y.Plugin.RecordsetFilter</code></dt>
    <dd>
        The default ModelList implementation only supports a <code>filter(function)</code>
        method.  If you were relying on this plugin's <code>grep</code> or <code>reject</code>
        methods or the <code>filter(key, value)</code> functionality, you will need to
        replace that functionality through custom code.
    </dd>

    <dt><code>Y.Plugin.RecordsetIndexer</code></dt>
    <dd>
        The default ModelList implementation does not support multiple custom
        indexes, though it does maintain an index for <code>id</code> (or another,
        assigned primary key attribute) and <code>clientId</code>.  See
        <a href="../model/index.html">the Model user guide</a> for more
        information on customizing the primary index.  If multiple custom
        indexes are required, DataTable supports the use of
        <a href="#recordtype">custom Model subclasses</a> to store the record
        data.
    </dd>
</ul>

<p>
    See the <a href="#data">Data Configuration section</a> of the DataTable
    user guide for more information.
</p>

<h2 id="features">Feature Configuration Changes</h2>

<p>
    The two optional features available for DataTable in 3.4.1 were sorting and
    scrolling.  Both features exist in 3.5.0, but are implemented as class
    extensions for <code>Y.DataTable</code>.  Simply including the <code>datatable-sort</code> or
    <code>datatable-scroll</code> module in your <code>use(...)</code> will enable the feature for
    all new DataTables.
</p>

<pre class="code prettyprint">YUI().use(&#x27;datatable-sort&#x27;, &#x27;datatable-scroll&#x27;, function (Y) {

    &#x2F;&#x2F; Create a DataTable that is sortable by the &quot;name&quot; column, and is
    &#x2F;&#x2F; configured to scroll vertically within 300px.  Because scrollable is
    &#x2F;&#x2F; set to &quot;y&quot;, not &quot;x&quot; or &quot;xy&quot;, it will not attempt to scroll horizontally.
    &#x2F;&#x2F; Instead the table width will be set to 100%.
    var table = new Y.DataTable({
        columns   : [ { key: &#x27;name&#x27;, sortable: true }, ... ],
        data      : [ ... ],
        scrollable: &quot;y&quot;,
        height    : &quot;300px&quot;,
        width     : &quot;100%&quot;
    });

    &#x2F;&#x2F; No plugins necessary
    table.render(&#x27;#over-there&#x27;);
});</pre>


<h3 id="sorting">Column Sorting Changes</h3>

<p>
    Configuring sortable columns may be done as it was in 3.4.1, by setting the
    column configuration property <code>sortable: true</code>, but may also be done by
    setting the DataTable's <code>sortable</code> configuration to <code>true</code> or an array of
    column names.
</p>

<div class="yui3-g">
    <div class="yui3-u before">
        <h4 class="no-toc">3.4.1</h4>

<pre class="code prettyprint">&#x2F;&#x2F; Assumes use(&#x27;datatable-sort&#x27;) or use(&#x27;datatable&#x27;)
var table = new Y.DataTable.Base({
    columnset: [
        { key: &quot;id&quot; },
        { key: &quot;name&quot;, sortable: true },
        { key: &quot;price&quot;, sortable: true }
    ],
    recordset: [
        { id: 1, name: &quot;Bread&quot;, price: 3.45 },
        { id: 2, name: &quot;Milk&quot;,  price: 4.99 },
        { id: 3, name: &quot;Eggs&quot;,  price: 2.75 },
        ...
    ],
    caption: &quot;Price List&quot;
});

table.plug(Y.Plugin.DataTableSort);

table.render(&#x27;#sort-demo&#x27;);

&#x2F;&#x2F; Sorting API is on the Recordset&#x27;s plugin
table.get(&quot;recordset&quot;).sort.sort(&quot;name&quot;);</pre>

    </div>
    <div class="yui3-u after">
        <h4 class="no-toc">3.5.0</h4>

<pre class="code prettyprint">&#x2F;&#x2F; Assumes use(&#x27;datatable-sort&#x27;) or use(&#x27;datatable&#x27;)
var table = new Y.DataTable({
    columns: [ &quot;id&quot;, &quot;name&quot;, &quot;price&quot; ],
    data: [
        { id: 1, name: &quot;Bread&quot;, price: 3.45 },
        { id: 2, name: &quot;Milk&quot;,  price: 4.99 },
        { id: 3, name: &quot;Eggs&quot;,  price: 2.75 },
        ...
    ],
    sortable: [ &quot;name&quot;, &quot;price&quot; ]
});

table.render(&#x27;#sort-demo&#x27;);

&#x2F;&#x2F; Sort method is on the instance
table.sort(&quot;name&quot;);

&#x2F;&#x2F;-------------------------------------------------
&#x2F;&#x2F; Alternate methods
&#x2F;&#x2F;-------------------------------------------------

var table = new Y.DataTable({
    columns: [ &quot;id&quot;, &quot;name&quot;, &quot;price&quot; ],
    data: [ ... ],
    sortable: true &#x2F;&#x2F; makes all columns sortable
});

&#x2F;&#x2F; OR the old way works, too
var table = new Y.DataTable({
    columns: [
        { key: &quot;id&quot; },
        { key: &quot;name&quot;, sortable: true },
        { key: &quot;price&quot;, sortable: true }
    ],
    data: [ ... ]
});</pre>

    </div>
</div>

<p>
    Since there is no plugin, the <code>sort</code> method is now on the DataTable instance
    itself, as are the related attributes.  In particular, the <code>lastSortedBy</code>
    attribute from the plugin implementation has been replaced by the <code>sortBy</code>
    attribute added by the class extension.
</p>

<p>
    As of 3.5.0, DataTables configured with <code>sortBy</code> will have their rows
    sorted automatically upon inserting into the table.  You do not need to
    presort data for the initial render.
</p>

<p>
    <strong>The <code>trigger</code> attribute of the sorting plugin was not retained in
    the 3.5.0 class extension</strong>.  If you require an alternate triggering
    event, detach and replace the table's <code>_sortHandle</code> property after
    <code>render()</code>.
</p>

<pre class="code prettyprint">var table = new Y.DataTable({ ... }).render(&quot;#over-there&quot;);

table._sortHandle.detach();
table._sortHandle = table.delegate([&quot;dblclick&quot;, &quot;keydown&quot;],
    table._onUITriggerSort, &quot;.yui3-datatable-sortable-column&quot;, table);</pre>


<p>
    See the <a href="index.html#sorting">Column Sorting section</a> of the 
    user guide for details about the APIs and attributes.
</p>

<h3 id="scrolling">Scrollable Table Changes</h3>

<p>
    Like sorting, the scrolling functionality has been moved to a class
    extension, making it unnecessary to plug the DataTable instance with the
    (now deprecated) <code>Y.Plugin.DataTableScroll</code> plugin.
</p>

<p>
    <strong><code>datatable-scroll</code> is no longer included in the <code>datatable</code>
    rollup</strong>, and must be explicitly included in your <code>use()</code> statement.
</p>

<p>
    To enable scrolling in 3.5.0, set the table's <code>scrollable</code> attribute to "x",
    "y", or "xy".  The configured <code>height</code> and <code>width</code> for the DataTable are
    used to bound the overall widget dimesions.  Scrolling will only be applied
    on the axis or axes specified in <code>scrollable</code>.  However, if <code>scrollable</code> is
    set to "y", but the <code>height</code> isn't set, it will not be made scrollable.
    Likewise for "x" and <code>width</code>.
</p>

<div class="yui3-g">
    <div class="yui3-u before">
        <h4 class="no-toc">3.4.1</h4>

<pre class="code prettyprint">&#x2F;&#x2F; Assumes use(&quot;datatable-scroll&quot;) or use(&quot;datatable&quot;)
var table = new Y.DataTable.Base({
    columnset: [&quot;id&quot;, &quot;name&quot;, &quot;price&quot;],
    recordset: [
        { id: 1, name: &quot;Bread&quot;, price: 3.45 },
        { id: 2, name: &quot;Milk&quot;,  price: 4.99 },
        { id: 3, name: &quot;Eggs&quot;,  price: 2.75 },
        ...
    ]
});

table.plug(Y.Plugin.DataTableScroll, {
    height: &quot;175px&quot;
});

table.render(&quot;#over-there&quot;);</pre>

    </div>
    <div class="yui3-u after">
        <h4 class="no-toc">3.5.0</h4>

<pre class="code prettyprint">&#x2F;&#x2F; Assumes use(&quot;datatable-scroll&quot;)
var table = new Y.DataTable({
    columns: [&quot;id&quot;, &quot;name&quot;, &quot;price&quot;],
    data: [
        { id: 1, name: &quot;Bread&quot;, price: 3.45 },
        { id: 2, name: &quot;Milk&quot;,  price: 4.99 },
        { id: 3, name: &quot;Eggs&quot;,  price: 2.75 },
        ...
    ],
    scrollable: &quot;y&quot;,
    height: &quot;175px&quot;
}).render(&quot;#over-there&quot;);</pre>

    </div>
</div>

<h2 id="markup">Markup and CSS Changes</h2>

<p>
    DataTable in 3.5.0 applies more CSS classes to Nodes, stamps fewer nodes
    with guid ids, and does not render header and cell liner <code>&lt;div&gt;</code>s.
</p>

<p>
    Below are examples of the same table rendered in 3.4.1 and 3.5.0.  The 3.5.0
    table has comments indicating markup added by feature modules.
</p>

<h4 class="no-toc">3.4.1</h4>
<pre class="code prettyprint">&lt;div id=&quot;(guid)&quot; class=&quot;yui3-widget yui3-datatable&quot;&gt;
  &lt;div id=&quot;(guid)&quot; class=&quot;yui3-datatable-content&quot;&gt;
    &lt;table&gt;

      &lt;caption&gt;
        Example table with simple columns
      &lt;&#x2F;caption&gt;

      &lt;colgroup&gt;
        &lt;col&gt;
        &lt;col&gt;
        &lt;col&gt;
      &lt;&#x2F;colgroup&gt;

    &lt;thead class=&quot;yui3-datatable-columns&quot;&gt;
      &lt;tr id=&quot;&quot; class=&quot;yui3-datatable-first yui3-datatable-last&quot;&gt;
        &lt;th id=&quot;(guid)&quot; rowspan=&quot;1&quot; colspan=&quot;1&quot; class=&quot;yui3-column-id&quot; abbr=&quot;&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            id
          &lt;&#x2F;div&gt;
        &lt;&#x2F;th&gt;
        &lt;th id=&quot;(guid)&quot; rowspan=&quot;1&quot; colspan=&quot;1&quot; class=&quot;yui3-column-name&quot; abbr=&quot;&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            name
          &lt;&#x2F;div&gt;
        &lt;&#x2F;th&gt;
        &lt;th id=&quot;(guid)&quot; rowspan=&quot;1&quot; colspan=&quot;1&quot; class=&quot;yui3-column-price&quot; abbr=&quot;&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            price
          &lt;&#x2F;div&gt;
        &lt;&#x2F;th&gt;
      &lt;&#x2F;tr&gt;
    &lt;&#x2F;thead&gt;

    &lt;tbody class=&quot;yui3-datatable-msg&quot;&gt;
    &lt;&#x2F;tbody&gt;

    &lt;tbody class=&quot;yui3-datatable-data&quot; id=&quot;(guid)&quot;&gt;
      &lt;tr id=&quot;(guid)&quot; class=&quot;yui3-datatable-even&quot;&gt;
        &lt;td headers=&quot;(guid)&quot; class=&quot;yui3-column-id&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            1
          &lt;&#x2F;div&gt;
        &lt;&#x2F;td&gt;
        &lt;td headers=&quot;(guid)&quot; class=&quot;yui3-column-name&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            Bread
          &lt;&#x2F;div&gt;
        &lt;&#x2F;td&gt;
        &lt;td headers=&quot;(guid)&quot; class=&quot;yui3-column-price&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            3.45
          &lt;&#x2F;div&gt;
        &lt;&#x2F;td&gt;
      &lt;&#x2F;tr&gt;
      &lt;tr id=&quot;(guid)&quot; class=&quot;yui3-datatable-odd&quot;&gt;
        &lt;td headers=&quot;(guid)&quot; class=&quot;yui3-column-id&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            2
          &lt;&#x2F;div&gt;
        &lt;&#x2F;td&gt;
        &lt;td headers=&quot;(guid)&quot; class=&quot;yui3-column-name&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            Milk
          &lt;&#x2F;div&gt;
        &lt;&#x2F;td&gt;
        &lt;td headers=&quot;(guid)&quot; class=&quot;yui3-column-price&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            4.99
          &lt;&#x2F;div&gt;
        &lt;&#x2F;td&gt;
      &lt;&#x2F;tr&gt;
      &lt;tr id=&quot;(guid)&quot; class=&quot;yui3-datatable-even&quot;&gt;
        &lt;td headers=&quot;(guid)&quot; class=&quot;yui3-column-id&quot;&gt;
          &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
            3
          &lt;&#x2F;div&gt;
        &lt;&#x2F;td&gt;
        &lt;td headers=&quot;(guid)&quot; class=&quot;yui3-column-name&quot;&gt;
            &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
              Eggs
            &lt;&#x2F;div&gt;
          &lt;&#x2F;td&gt;
          &lt;td headers=&quot;(guid)&quot; class=&quot;yui3-column-price&quot;&gt;
            &lt;div class=&quot;yui3-datatable-liner&quot;&gt;
              2.75
            &lt;&#x2F;div&gt;
          &lt;&#x2F;td&gt;
        &lt;&#x2F;tr&gt;
      &lt;&#x2F;tbody&gt;

    &lt;&#x2F;table&gt;
  &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;</pre>


<h4 class="no-toc">3.5.0</h4>
<pre class="code prettyprint">&lt;div id=&quot;(guid)&quot; class=&quot;yui3-widget yui3-datatable&quot;&gt;
  &lt;div id=&quot;(guid)&quot; class=&quot;yui3-datatable-content&quot;&gt;
    &lt;table cellspacing=&quot;0&quot; class=&quot;yui3-datatable-table&quot; id=&quot;(guid)&quot;&gt;

      &lt;caption class=&quot;yui3-datatable-caption&quot;&gt;
        Price List
      &lt;&#x2F;caption&gt;
  
      &lt;!-- colgroup only renders if datatable-column-widths is use()d.
           Note, datatable-column-widths is included in the datatable rollup --&gt;
      &lt;colgroup id=&quot;(guid)&quot;&gt;
        &lt;col&gt;
        &lt;col&gt;
        &lt;col&gt;
      &lt;&#x2F;colgroup&gt;
  
      &lt;thead class=&quot;yui3-datatable-columns&quot; id=&quot;(guid)&quot;&gt;
        &lt;tr&gt;
          &lt;th id=&quot;(guid)&quot; colspan=&quot;1&quot; rowspan=&quot;1&quot; class=&quot;yui3-datatable-header yui3-datatable-first-header yui3-datatable-col-id&quot; scope=&quot;col&quot; data-yui3-col-id=&quot;id&quot;&gt;
            id
          &lt;&#x2F;th&gt;
          &lt;th id=&quot;(guid)&quot; colspan=&quot;1&quot; rowspan=&quot;1&quot; class=&quot;yui3-datatable-header yui3-datatable-col-name&quot; scope=&quot;col&quot; data-yui3-col-id=&quot;name&quot;&gt;
            name
          &lt;&#x2F;th&gt;
          &lt;th id=&quot;(guid)&quot; colspan=&quot;1&quot; rowspan=&quot;1&quot; class=&quot;yui3-datatable-header yui3-datatable-col-price&quot; scope=&quot;col&quot; data-yui3-col-id=&quot;price&quot;&gt;
            price
          &lt;&#x2F;th&gt;
        &lt;&#x2F;tr&gt;
      &lt;&#x2F;thead&gt;

      &lt;!-- The message tbody only renders if datatable-message is use()d.
           Note, datatable-message is included in the datatable rollup --&gt;
      &lt;tbody class=&quot;yui3-datatable-message&quot; id=&quot;(guid)&quot;&gt;
        &lt;tr&gt;
          &lt;td class=&quot;yui3-datatable-message-content&quot; colspan=&quot;3&quot;&gt;
            No data to display
          &lt;&#x2F;td&gt;
        &lt;&#x2F;tr&gt;
      &lt;&#x2F;tbody&gt;

      &lt;tbody class=&quot;yui3-datatable-data&quot;&gt;
        &lt;tr id=&quot;(guid)&quot; data-yui3-record=&quot;record_1&quot; class=&quot;yui3-datatable-even&quot;&gt;
          &lt;td class=&quot;yui3-datatable-col-id  yui3-datatable-cell&quot;&gt;
            1
          &lt;&#x2F;td&gt;
          &lt;td class=&quot;yui3-datatable-col-name  yui3-datatable-cell&quot;&gt;
            Bread
          &lt;&#x2F;td&gt;
          &lt;td class=&quot;yui3-datatable-col-price  yui3-datatable-cell&quot;&gt;
            3.45
          &lt;&#x2F;td&gt;
        &lt;&#x2F;tr&gt;
        &lt;tr id=&quot;(guid)&quot; data-yui3-record=&quot;record_2&quot; class=&quot;yui3-datatable-odd&quot;&gt;
          &lt;td class=&quot;yui3-datatable-col-id  yui3-datatable-cell&quot;&gt;
            2&lt;&#x2F;td&gt;
          &lt;td class=&quot;yui3-datatable-col-name  yui3-datatable-cell&quot;&gt;
            Milk
          &lt;&#x2F;td&gt;
          &lt;td class=&quot;yui3-datatable-col-price  yui3-datatable-cell&quot;&gt;
            4.99
          &lt;&#x2F;td&gt;
        &lt;&#x2F;tr&gt;
        &lt;tr id=&quot;(guid)&quot; data-yui3-record=&quot;record_3&quot; class=&quot;yui3-datatable-even&quot;&gt;
          &lt;td class=&quot;yui3-datatable-col-id  yui3-datatable-cell&quot;&gt;
            3
          &lt;&#x2F;td&gt;
          &lt;td class=&quot;yui3-datatable-col-name  yui3-datatable-cell&quot;&gt;
            Eggs
          &lt;&#x2F;td&gt;
          &lt;td class=&quot;yui3-datatable-col-price  yui3-datatable-cell&quot;&gt;
            2.75
          &lt;&#x2F;td&gt;
        &lt;&#x2F;tr&gt;
      &lt;&#x2F;tbody&gt;

    &lt;&#x2F;table&gt;
  &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;</pre>


<h2 id="help-me">What Did I Miss?</h2>

<p>
    Obviously, there were a lot of changes to DataTable from 3.4.1 to 3.5.0.
    It's entirely likely that I have missed something here.  If you experience
    trouble with your upgrade and find this migration guide is missing
    something important, please <a href="/projects/yui3/newticket">file a
    ticket</a> and I'll update it as soon as possible.
</p>

<p>
    Additional resources to help with the upgrade include the
    <a href="/forum">forums</a>, and the #yui IRC channel on freenode.net.
</p>
</div>
            </div>
        </div>

        <div class="yui3-u-1-4">
            <div class="sidebar">
                
                    <div id="toc" class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Table of Contents</h2>
                        </div>

                        <div class="bd">
                            <ul class="toc">
<li>
<a href="#overview">Overview of API changes from 3.4.1</a>
</li>
<li>
<a href="#instantiation">Instantiation and Instance Configuration Changes</a>
</li>
<li>
<a href="#formatters">Table and Cell Formatting Changes</a>
</li>
<li>
<a href="#columns">Column Configuration Changes</a>
</li>
<li>
<a href="#data">Row Data Configuration Changes</a>
</li>
<li>
<a href="#features">Feature Configuration Changes</a>
<ul class="toc">
<li>
<a href="#sorting">Column Sorting Changes</a>
</li>
<li>
<a href="#scrolling">Scrollable Table Changes</a>
</li>
</ul>
</li>
<li>
<a href="#markup">Markup and CSS Changes</a>
</li>
<li>
<a href="#help-me">What Did I Miss?</a>
</li>
</ul>
                        </div>
                    </div>
                

                
                    <div class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Examples</h2>
                        </div>

                        <div class="bd">
                            <ul class="examples">
                                
                                    
                                        <li data-description="This example illustrates simple DataTable use cases.">
                                            <a href="datatable-basic.html">Basic DataTable</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="DataTable loaded with JSON data from a remote webservice via DataSource.Get">
                                            <a href="datatable-dsget.html">DataTable + DataSource.Get + JSON Data</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="DataTable loaded with XML data from a remote webservice via DataSource.IO.">
                                            <a href="datatable-dsio.html">DataTable + DataSource.IO + XML Data</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Custom format data for display.">
                                            <a href="datatable-formatting.html">Formatting Row Data for Display</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="DataTable with nested column headers.">
                                            <a href="datatable-nestedcols.html">Nested Column Headers</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="DataTable with column sorting.">
                                            <a href="datatable-sort.html">Column Sorting</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="DataTable with vertical and/or horizontal scrolling rows.">
                                            <a href="datatable-scroll.html">Scrolling DataTable</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Using DataTable&#x27;s recordType attribute to create calculated, sortable columns.">
                                            <a href="datatable-recordtype.html">Sortable generated columns</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Populating one DataTable from details in the data of another.">
                                            <a href="datatable-masterdetail.html">Master and detail tables</a>
                                        </li>
                                    
                                
                                    
                                        <li data-description="Checkbox column that retains checked state when sorting.">
                                            <a href="datatable-chkboxselect.html">Checkbox select column</a>
                                        </li>
                                    
                                
                                    
                                
                            </ul>
                        </div>
                    </div>
                

                
                    <div class="sidebox">
                        <div class="hd">
                            <h2 class="no-toc">Examples That Use This Component</h2>
                        </div>

                        <div class="bd">
                            <ul class="examples">
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                        <li data-description="Shows how to instantiate multiple Panel instances, and use nested modality to interact with a Datatable.">
                                            <a href="../panel/panel-form.html">Creating a Modal Form</a>
                                        </li>
                                    
                                
                            </ul>
                        </div>
                    </div>
                
            </div>
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

<script>
YUI.Env.Tests = {
    examples: [],
    project: '../assets',
    assets: '../assets/datatable',
    name: 'datatable',
    title: '3.5.0+ Migration Guide',
    newWindow: '',
    auto:  false 
};
YUI.Env.Tests.examples.push('datatable-basic');
YUI.Env.Tests.examples.push('datatable-dsget');
YUI.Env.Tests.examples.push('datatable-dsio');
YUI.Env.Tests.examples.push('datatable-formatting');
YUI.Env.Tests.examples.push('datatable-nestedcols');
YUI.Env.Tests.examples.push('datatable-sort');
YUI.Env.Tests.examples.push('datatable-scroll');
YUI.Env.Tests.examples.push('datatable-recordtype');
YUI.Env.Tests.examples.push('datatable-masterdetail');
YUI.Env.Tests.examples.push('datatable-chkboxselect');
YUI.Env.Tests.examples.push('panel-form');

</script>
<script src="../assets/yui/test-runner.js"></script>



</body>
</html>