Skip to content

Instantly share code, notes, and snippets.

@stlsmiths
Created August 9, 2012 15:46
Show Gist options
  • Save stlsmiths/3305298 to your computer and use it in GitHub Desktop.
Save stlsmiths/3305298 to your computer and use it in GitHub Desktop.
one-off extension of DataTableDataSource plugin ...
// Need to create a one-time extension of DataTableDataSource Plugin,
DTDSAddPag = Y.Base.create('datasourcepag', Y.Plugin.DataTableDataSource, [], {
// Need to override this base method ...
onDataReturnInitializeTable: function(e) {
var records = (e.response && e.response.results) || [];
// Add this to update the DS state
this.set('state', e.response.meta );
this.get("host").set("data", records);
}
},{
// It's a plugin, so it needs these specified ...
NAME: 'datatableDataSourcePag',
NS: 'datasourcepag',
// Need two new attributes to be added ...
ATTRS:{
queryStringTemplate : {
value: null
},
state: {
value: {
startIndex: 0,
numRecs: 0
}
}
}
});
// Now use all this stuff ...
var myDS = new Y.DataSource.IO(...);
myDS.plug(Y.Plugin.DataSourceJSONSchema, { ... });
var myDT = new Y.DataTable(...);
myDT.plug( DTDSAddPag, {
datasource: ds,
initialRequest: '?iopt=getdata&startIndex=0&numRecs=500',
queryStringTemplate: '?iopt=getdata&startIndex={startIndex}&numRecs={numRecs}'
});
myDT.render(...);
myDT.datasource.load(...);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment