Skip to content

Instantly share code, notes, and snippets.

@jenny
Created May 1, 2010 01:57
Show Gist options
  • Save jenny/385960 to your computer and use it in GitHub Desktop.
Save jenny/385960 to your computer and use it in GitHub Desktop.
YUI().use("datasource", "yui2-datatable", "yui2-paginator", function(Y) {
var YAHOO = Y.YUI2;
/* Compat for 3.0 */
Y.DataSource.Local.issueCallback = function(e) {
var callback = e.callback,
error = e.error,
params = (error) ? [e.request, {error:true}] : [e.request,e.response],
scope = e.callback.scope;
if (Y.Lang.isFunction(callback)) {
callback.apply(scope, params);
} else if (Y.Lang.isObject(callback)) {
scope = callback.scope || scope || window;
var callbackFunc = callback.success;
if (error) {
callbackFunc = callback.failure;
}
if (callbackFunc) {
callbackFunc.apply(scope, params.concat([callback.argument]));
}
}
};
/* Updated for 3.1 */
var sendRequest3_1 = Y.DataSource.Local.prototype.sendRequest;
Y.DataSource.Local.prototype.sendRequest = function(r, c) {
sendRequest3_1.apply(this, [{request:r, callback:c}]);
};
var myColumnDefs = [{key:"SKU"},{key:"Quantity"},{key:"Item"},{key:"Description"},{key:"Url"}];
var myDataSource = new Y.DataSource.Local({
source: [
{SKU:"23-23874", Quantity:43, Item:"Helmet", Description:"Red baseball helmet. Size: Large. Strings_with_underscores_don't-wrap.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"48-38835", Quantity:84, Item:"Football", Description:"Leather football. Hyphenated-strings-do-not-wrap-either.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"84-84848", Quantity:31, Item:"Goggles", Description:"Light blue swim goggles Neither.do.strings.with.periods.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"84-84843", Quantity:56, Item:"Badminton Set", Description:"Set of 2 badminton rackets, net, and 3 birdies.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"84-39321", Quantity:128, Item:"Tennis Balls", Description:"Canister of 3 tennis balls.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"39-48949", Quantity:55, Item:"Snowboard", Description:"", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"99-28128", Quantity:77, Item:"Cleats", Description:"Soccer cleats. Size: 10.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"83-48281", Quantity:65, Item:"Volleyball", Description:"", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"89-32811", Quantity:12, Item:"Sweatband", Description:"Blue sweatband. Size: Medium.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"28-22847", Quantity:43, Item:"Golf Set", Description:"Set of 9 golf clubs and bag.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"38-38281", Quantity:1, Item:"Basketball Shorts", Description:"Green basketball shorts. Size: Small.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"82-38333", Quantity:288, Item:"Lip balm", Description:"Lip balm. Flavor: Cherry.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"21-38485", Quantity:177, Item:"Ping Pong Ball", Description:"", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"},
{SKU:"21-38485", Quantity:87, Item:"Hockey Puck", Description:"Glow-in-the-dark hockey puck.", Url:"http://very-long-non-breaking-url-on-single-line?productId=1234567890"}
],
responseSchema: {
fields: ["SKU","Quantity","Item","Description","Url"]
}
});
var myDataTable = new YAHOO.widget.DataTable("myContainer", myColumnDefs, myDataSource, {
paginator: new YAHOO.widget.Paginator({
rowsPerPage: 5
}),
renderLoopSize: 50
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment