Skip to content

Instantly share code, notes, and snippets.

var datasource = new Y.DataSource.IO({ source: ... });
datasource.on('data', function (e) {
var raw = Y.JSON.parse(e.data),
data = [],
key;
for (key in raw.pathToDataObject) {
if (raw.pathToDataObject[key]) {
data.push(raw.pathToDataObject[key]);
}
@lsmith
lsmith / gist:2494497
Created April 25, 2012 23:42
Flyweight proxy ArrayList for fast DataTable instantiation and rendering
var proxy = {
_data: {},
get: function (name) {
var model = this._data;
return model.isYUIModel ?
model.apply(model, arguments) :
model[name];
},
set: function () {
@lsmith
lsmith / gist:2480921
Created April 24, 2012 15:51 — forked from stlsmiths/gist:2480907
POC DataTable.Selection class extension
// Class extension to DataTable ...
Y.DataTable.Selection = function () {}
Y.DataTable.Selection.ATTRS = {
// selectionMode: for supporting multiple selection could be its own extension
selectionType: {
value: null, // Feature should not change base behavior by default
validator: '_validateSelectionType'
// Adding a title attribute to a DataTable cell with a cellTemplate and a formatter
new Y.DataTable({
columns: [
{
key: 'foo',
allowHTML: true,
// Notice the lack of > before {content}
cellTemplate: '<td class="{className}"{headers} {content}</td>',
formatter: function (o) {
// the > is included in the cell content string returned from the formatter. allowHTML is required.
@lsmith
lsmith / gist:2375130
Created April 13, 2012 08:37
Ye Olde brainstorm about IO API

Data normalization API proposal

Data API normalization/centralization in three layers

  1. transport layer

  2. transaction layer

  3. encapsulated configuration layer (aka Resource/DataSource)

  4. Transport layer

@lsmith
lsmith / gist:2372050
Created April 13, 2012 00:07
Bare bones class for 3.5.0 DataTable's recordType = faster render
// Until some planned performance enhancements are applied to DataTable's infrastructure,
// this is a quick hack to improve rendering performance if it's needed:
// Some quacking will be needed for the various places where duck-typing is used
function DumbRecord(data) {
this.data = data;
this._id = 'record_' + DumbRecord._id++;
this.lists = []; // quack
}
@lsmith
lsmith / gist:2295032
Created April 3, 2012 19:42
Mutation optimization for YUI 3 DataTable
// Include this after the table's render()
// CAVEAT: this is NOT compatible with nodeFormatters
table.body._afterDataChange = function (e) {
var type = (e.type.match(/:(add|remove|change)$/) || [])[1],
odd = ['yui3-datatable-odd', 'yui3-datatable-even'],
even = ['yui3-datatable-even', 'yui3-datatable-odd'],
row, index;
switch (type) {
case 'change':
@lsmith
lsmith / gist:2244450
Created March 29, 2012 22:38
Keyboard navigable DataTable rows with selection
/*
This code should allow users to tab to the first row in the table, which will "select" it by
adding a class to it and storing a reference to the row node. Alternately, users can click
on a row to select it. Selection can be shifted to the next or previous row with the up and down arrow keys. The 'enter' key will fire a 'rowAction' custom event.
*/
table.getRow(0).setAttribute('tabindex', table.get('tabIndex') || 0);
table.delegate('keydown', function (e) {
var selected = this._selectedRow,
tbody = this._tbodyNode,
@lsmith
lsmith / gist:2151800
Created March 21, 2012 19:35
Workaround for datatable.getColumn(node) (#2531924)
// Add support for table.getColumn( node )
Y.DataTable.prototype.getColumn = (function (original) {
return function (seed) {
var cell;
if (Y.instanceof(seed, Y.Node)) {
cell = this.getCell(seed);
seed = cell && (cell.get('className').match(
new RegExp(this.getClassName('col', '(\\w+)'))) || [])[1];
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>test page</title>
<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/3.4.1/build/cssreset/cssreset-min.css" id="changeme">
</head>
<body>
<h1>This is a heading</h1>