Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lsmith/168448 to your computer and use it in GitHub Desktop.
Save lsmith/168448 to your computer and use it in GitHub Desktop.
// How to rename DataTable columns from data in a server response
// This example assumes server response JSON looking like this:
{ records: [...], columnLabels: ['1/1/2009','1/2/2009','1/3/2009',...] }
// Add a convenience method onto the Column prototype
YAHOO.widget.Column.prototype.setLabel = function (label) {
var el = YAHOO.util.Dom.getElementsByClassName('yui-dt-label', 'span', this.getThLinerEl())[0];
// The label needing updating could be a span or an anchor element for
// sortable columns
el = el.getElementsByTagName('a')[0] || el;
this.label = el.innerHTML = label;
};
// Set up the DataSource responseSchema.metaFields to capture the label collection
myDataSource.responseSchema.metaFields = {
labels: 'columnLabels'
};
...
myDataTable.subscribe('dataReturnEvent', function (o) {
var cols = this.getColumnSet().getDefinitions().
labels = o.response.meta.labels;
for (i = cols.length - 1; i >= 0; --i) {
this.getColumn(cols[i].key).setLabel(labels[i]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment