Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created April 30, 2012 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsmith/0e28d17c05564b94ca9e to your computer and use it in GitHub Desktop.
Save lsmith/0e28d17c05564b94ca9e to your computer and use it in GitHub Desktop.
// Create a custom subclass of View with a very simple rendering algorithm
var RowRowRowYourView = Y.Base.create('tableBody', Y.View, [], {
render: function () {
var tbody = this.get('container'),
rowData = this.get('modelList'),
content = '';
rowData.each(function (rowModel, index) {
var stripe = index % 2 ? 'odd' : 'even',
template = '<tr class="' + (index % 2 ? 'odd' : 'even') + '">' +
'<td>{username}</td><td>{first}</td><td>{last}</td>' +
'</tr>';
content += Y.Lang.sub(template, rowModel.toJSON());
});
tbody.setHTML(content);
return this;
}
});
var table = new Y.DataTable({
data: [ ... ],
columns: [ ... ],
bodyView: RowRowRowYourView
}).render('#over-there');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment