Skip to content

Instantly share code, notes, and snippets.

@ghinch
Created September 11, 2010 16:58
Show Gist options
  • Save ghinch/575358 to your computer and use it in GitHub Desktop.
Save ghinch/575358 to your computer and use it in GitHub Desktop.
var Book = Y.Base.create('book', Y.Model, [], {}, {
ATTRS : { // use the normal attribute config here, including the validation & parsing (setter)
author : {},
title : {},
publisher : {}
},
EDITORS : { // define editors for each key here
author : {fn : Y.Model.EDIT.Choice, cfg : {choices : [...]},
title : Y.Model.EDIT.Text
}
RENDERERS : { // similarly define render methods for each key here
}
});
var ds = new Y.DataSource.Local({source : data});
ds.plug(Y.Plugin.DataSourceArraySchema); // resultFields will be derived from the Model
var qm = new Y.QueryManager({source : ds, model : Book}); // sets up the ds to return its data as models
var dt = new Y.DataTable({cols : ['author', 'title', 'publisher']}); // Optionally set cols here if you don't want to display all
qm.after('dataParsed', function (e) {
dt.setRows(e.data); // e.data being an array of Book instances
});
// what's nice here is the query manager could then store the query state and subsequent/
// requests only need to send what's changed (eg: qm.sendRequest({page : 2}))
qm.sendRequest({
page : 1,
perPage : 50,
col : 'author',
dir : 'asc'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment