datatable.html revision 75365cf641880c18abb494d5a5aa6c4dedde96be
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<link rel="stylesheet" type="text/css" href="/build/cssbase/base-min.css">
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync font-family: sans-serif;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync font-size: smaller;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync padding: 5px;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync font-size:120%;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync background: #FFFCB6;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync border:1px solid #C9C675;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync #results dt {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync font-weight:bold;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync padding:3px;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync display:block;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync #results dd {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync font-weight:normal;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync color:grey;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync #results dd span {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync color: red;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync font-weight:bold;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<p>To test the performance of various datatables, look at the following sections in the code:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync//large or small dataset.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncdata: large,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync//---------------------------------------------
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync// Special instructions
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync//---------------------------------------------
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync //ignore following tests (good to do if you are doing a large dataset)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync testBaseDatatable: true,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync testXYDatatable: true,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync testXDatatable: true,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync testYDatatable_FixedCol: true,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync testYDatatable_AutoCol: true,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync testXYDatatable_BigHeaders: false
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync Toggle <code>data</code> from <code>large</code> to <code>small</code> to get a different sized dataset. The <code>ignore</code> object determines which table to load. If testing performance, it is recommended that you only enable 1 table at a time.</p>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<p><input type="button" value="Run Tests" id="btnRun" disabled=true></p>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<P>A general XY scrolling datatable. Column widths are provided for all columns, table width and height is provided.</p>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<p>A X-scrolling datatable. Column A and B have specified widths. The rest of the columns do not have any widths specified. Only a height of 200px is specified.</p>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<p>A Y-scrolling datatable. Column widths are provided for all columns, table height is provided. Since all cols have specified width, you may see this table overflowing past its container div (the blue div in the background). </p>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<p>A Y-scrolling datatable, where only the first 2 columns have a specified width. Only the table height is provided.</p>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<p>A XY-scrolling datatable, where only the first 2 columns have a specified width. Table height and width is provided. The table headers are of larger width than the table contents</p>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<h3>Scrolling Datatable with no width or height set</h3>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<p>A scrolling datatable with no width or height values passed in will result in a base datatable being created with auto width and height.</p>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync(function() {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min',
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync allowRollup: false,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync useBrowserConsole: false
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync }).use("console", "test", "dump", "datatable", "profiler","node","json-parse", function(Y) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync // Set up the page
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync var ASSERT = Y.Assert,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync ARRAYASSERT = Y.ArrayAssert,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync BTNRUN = Y.one("#btnRun"),
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync BTNRUN.set("disabled", false);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync TestRunner.subscribe(TestRunner.TEST_CASE_COMPLETE_EVENT, testCompleted);
Y.on("click", function(e){
BTNRUN.set("value", 'Running...');
BTNRUN.set("disabled", true);
BTNRUN.set("value", 'Test Completed');
Y.log('Test Completed');
var myConsole = new Y.Console().render();
var small = [{a:3, b:2, c:1, d:6, e:7, f:2, g:0}, {a:9, b:8, c:7, d:6, e:7, f:2, g:0}, {a:1, b:2, c:3, d:6, e:7, f:2, g:0},
{a:3, b:2, c:1, d:6, e:7, f:2, g:0}, {a:9, b:8, c:7, d:6, e:7, f:2, g:0}, {a:1, b:2, c:3, d:6, e:7, f:2, g:0},
{a:3, b:2, c:1, d:6, e:7, f:2, g:0}, {a:9, b:8, c:7, d:6, e:7, f:2, g:0}, {a:1, b:2, c:3, d:6, e:7, f:2, g:0},
{a:3, b:2, c:1, d:6, e:7, f:2, g:0}, {a:9, b:8, c:7, d:6, e:7, f:2, g:0}, {a:1, b:2, c:3, d:6, e:7, f:2, g:0}];
cols: [{key:"a", field:"a", label:"AAA", sortable:true, className: ["oneClass", "anotherClass"], width:'75px'},{key:"b", abbr:"bbb", className:"myClass", width: '120px'},{key:"c", width:'75px'},{key:"d", width:'150px'},{key:"3", width:'75px'},{key:"f", width:'150px'},{key:"g", width:'75px'}],
cols2: [{key:"a", field:"a", label:"AAA", sortable:true, className: ["oneClass", "anotherClass"], width:'75px'},{key:"b", abbr:"bbb", className:"myClass", width:'75px'},{key:"c"},{key:"d"},{key:"e"},{key:"f"},{key:"g"}],
cols3: [{key:"a", field:"a", label:"Lorem Ipsum Dolor SIt Amet", sortable:true, className: ["oneClass", "anotherClass"], width:'5px'},{key:"b", abbr:"Lorem Ipsum Dolor SIt Amet", className:"myClass", width:'75px'},{key:"Lorem Ipsum Dolor SIt Amet"},{key:"Lorem Ipsum Dolor SIt Amet"},{key:"Lorem Ipsum Dolor SIt Amet"},{key:"Lorem Ipsum Dolor SIt Amet"},{key:"Lorem Ipsum Dolor SIt Amet"}],
var dd = Y.Node.create('<dd>' + v.calls + ' call(s) at ' + v.avg + ' ms/call = <span>' + Math.round(v.avg*v.calls) + '</span> ms total</dd>');
Y.Profiler.start('dtBase');
this.dt.render(sel);
Y.Profiler.stop('dtBase');
var msg = Y.Profiler.getAverage('dtBase') + 'ms taken to display';
this.displayReport(report);
Y.Profiler.unregisterObject('dt');
Y.log(msg, "time");
Y.Profiler.start('dtXY');
this.dt = new Y.DataTable.Base({columnset:this.cols, recordset:this.data, tdValueTemplate:"plug then render {value}", caption: "ScrollingDataTable"});
this.dt.render(sel);
Y.Profiler.stop('dtXY');
var msg = Y.Profiler.getAverage('dtXY') + 'ms taken to display';
this.displayReport(report);
Y.Profiler.unregisterObject('dt');
Y.log(msg, "time");
Y.Profiler.start('dtX');
this.dt = new Y.DataTable.Base({columnset:this.cols2, recordset:this.data, caption:"ScrollingDataTable"});
this.dt.render(sel);
Y.Profiler.stop('dtX');
var msg = Y.Profiler.getAverage('dtX') + 'ms taken to display';
this.displayReport(report);
Y.Profiler.unregisterObject('dt');
Y.log(msg, "time");
Y.Profiler.start('dtY1');
this.dt = new Y.DataTable.Base({columnset:this.cols, recordset:this.data, tdValueTemplate:"plug then render {value}", caption:"ScrollingDataTable"});
this.dt.render(sel);
Y.Profiler.stop('dtY1');
var msg = Y.Profiler.getAverage('dtY1') + 'ms taken to display';
this.displayReport(report);
Y.Profiler.unregisterObject('dt');
Y.log(msg, 'time');
Y.Profiler.start('dtY2');
this.dt = new Y.DataTable.Base({columnset:this.cols2, recordset:this.data, tdValueTemplate:"plug then render {value}", caption:"ScrollingDataTable"});
this.dt.render(sel);
Y.Profiler.stop('dtY2');
var msg = Y.Profiler.getAverage('dtY2') + 'ms taken to display';
this.displayReport(report);
Y.Profiler.unregisterObject('dt');
Y.log(msg, 'time');
Y.Profiler.start('dtHeaders');
this.dt = new Y.DataTable.Base({columnset:this.cols3, recordset:this.data, tdValueTemplate:"plug then render {value}", caption:"ScrollingDataTable"});
this.dt.render(sel);
Y.Profiler.stop('dtHeaders');
var msg = Y.Profiler.getAverage('dtHeaders') + 'ms taken to display';
this.displayReport(report);
Y.Profiler.unregisterObject('dt');
Y.log(msg, 'time');
Y.Profiler.start('dtNoScroll');
this.dt = new Y.DataTable.Base({columnset:this.cols3, recordset:this.data, tdValueTemplate:"plug then render {value}", caption:"ScrollingDataTable"});
this.dt.render(sel);
Y.Profiler.stop('dtNoScroll');
var msg = Y.Profiler.getAverage('dtNoScroll') + 'ms taken to display';
this.displayReport(report);
Y.Profiler.unregisterObject('dt');
Y.log(msg, 'time');
this.dt.scroll.set('width', '200px');
var a = new Y.DataTable.Base(),
b = new Y.DataTable.Base(),
aRS = a.get('recordset'),
bRS = b.get('recordset');
Y.Assert.areNotSame(aRS, bRS);
var container = Y.one("#base"),
table = new Y.DataTable.Base({
columnset: this.cols,
recordset: this.data,
table.render(container);
caption = table.get('boundingBox').one('caption');
Y.Assert.isNotNull(caption);
container.empty(true);
table = new Y.DataTable.Base({
columnset: this.cols,
recordset: this.data
table.render(container);
caption = table.get('boundingBox').one('caption');
Y.Assert.isNull(caption);
table.set('caption', 'Caption set');
caption = table.get('boundingBox').one('caption');
Y.Assert.isNotNull(caption);
"test table.datasource.load() updates UI": function () {
container = Y.one('#base'),
container.empty(true);
source = new Y.DataSource.Local({ source: data });
table = new Y.DataTable.Base({
table.render(container);
container = Y.one('#base'),
container.empty(true);
source = new Y.DataSource.Local({ source: data });
table = new Y.DataTable.Base({
table.render(container);
recordset = table.get("recordset");
Y.Assert.isObject(recordset);
container = Y.one('#base'),
container.empty(true);
table = new Y.DataTable.Base({
table.render(container);
html = table._theadNode.getContent();
"cells should default content from column.emptyCellValue": function () {
container = Y.one('#base'),
container.empty(true);
table = new Y.DataTable.Base({
table.render(container);
Y.Assert.isNull(table._tbodyNode
table._tbodyNode.all('tr').item(2)
// http://yuilibrary.com/projects/yui3/ticket/2529920#comment:18
container = Y.one('#base'),
container.empty(true);
table = new Y.DataTable.Base({
table.render(container);
cell = table._tbodyNode.one('.yui3-datatable-liner');
table.set('recordset', [
cell = table._tbodyNode.one('.yui3-datatable-liner');
var suite = new Y.Test.Suite("Datatable Test Suite");
suite.add(testBasic);
Y.Test.Runner.setName("Datatable Test Runner");
Y.Test.Runner.add(suite);