Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created March 27, 2009 18:56
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/86823 to your computer and use it in GitHub Desktop.
Save lsmith/86823 to your computer and use it in GitHub Desktop.
YAHOO.util.Event.onDOMReady(function () {
var Ex = YAHOO.namespace('example');
Ex.dataSource = new YAHOO.util.DataSource(YOUR_URL,{
responseType : YAHOO.util.DataSource.TYPE_JSON,
responseSchema : {
resultsList: 'records',
fields : ['foo','bar','baz'],
metaFields : { totalRecords: 'total' }
}
});
Ex.cols = [
{ key: 'foo', sortable: true },
{ key: 'bar', sortable: true },
{ key: 'baz', sortable: true }
];
Ex.paginator = new YAHOO.widget.Paginator({
rowsPerPage: 10
});
Ex.conf = {
initialRequest : 'gimme=10',
paginator : Ex.paginator,
dynamicData : true
};
Ex.dataTable = new YAHOO.widget.DataTable(ID,Ex.cols,Ex.dataSource,Ex.conf);
Ex.dataTable.handleDataReturnPayload = function (req,res,payload) {
payload.totalRecords = res.meta.totalRecords;
return payload;
};
Ex.dataTable.subscribe('dataReturnEvent', function () {
Ex.dataSource.sendRequest('gimme=THE_REST', {
success : function (req, res, payload) {
this.set('dynamicData',false);
this.addRows(res.records);
},
scope: Ex.dataTable
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment