Created
August 28, 2012 03:20
-
-
Save stlsmiths/3494655 to your computer and use it in GitHub Desktop.
Datatable paginator.view using ModelSync.REST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUI({ | |
filter:'raw', combine:false, | |
// paginator-view is on YUI Gallery | |
modules: { | |
'datatable-paginator': { | |
fullpath: "http://www.jbistudios.com/applicationdev/js/yui/build/datatable-paginator-class/datatable-paginator-class.js", | |
type: 'js', | |
requires: [ "datatable-base", "base-build", "event-custom" ] | |
} | |
/*, | |
'paginator-css' : { | |
fullpath: "http://jbistudios.com/applicationdev/js/yui/build/paginator-mv/assets/paginator-view.css", | |
type: "css" | |
}, | |
'paginator-mv': { | |
fullpath: "http://jbistudios.com/applicationdev/js/yui/build/paginator-mv/paginator-mv.js", | |
type: "js", | |
requires: [ "base-build", "model", "view", 'substitute', 'paginator-css' ] | |
} */ | |
} | |
} | |
).use('node', 'event', | |
'datatable-sort', 'datatable-scroll', 'cssfonts', 'model-sync-rest', | |
'datatable-paginator', 'paginator-mv', 'model', 'view', 'substitute', | |
'paginator-css', 'event-custom', 'base-build', 'datatable-base', 'json-parse', | |
function (Y) { | |
Y.on('domready', function() { | |
var viewPane = Y.one('#element-box > .m'); | |
var viewUri = '/applicationdev/administrator/index.php?option=com_wms&class=acctscontacts&format=json&' | |
+ 'numRecs={numRecs}&indexStart={startIndex}'; | |
Accounts = Y.Base.create('pulledaccounts', Y.Model, [], {}, { | |
ATTRS: { | |
sf_account_id:{}, account_name:{}, account_owner_id:{}, contact_city:{}, contact_state:{}, contact_phone:{} | |
} | |
}); | |
AccountList = Y.Base.create('accountlist', Y.ModelList,[Y.ModelSync.REST],{ | |
// url setup to handle extra passed-in options for pagination stuff ... | |
//url: '/data/musicPage?startIndex={startIndex}&numRecs={numRecs}&sortBy={sortBy}', | |
url: viewUri, | |
parse: function(resp) { | |
var parsed = Y.JSON.parse(resp), | |
results = []; | |
if ( parsed.replyCode === 200 && parsed.Results ) { | |
this.set('indexStart', parsed.indexStart); | |
this.set('pageRecs', parsed.pageRecords); | |
this.set('totalRecs', parsed.totalRecords); | |
results = parsed.Results | |
} | |
// Define my own event to fire after parsing completes .... in case I want to listen to it somewhere | |
this.fire('parsed', {resp:resp, parsed:parsed, results:results}); | |
return results; | |
} | |
},{ | |
ATTRS:{ | |
indexStart: {}, | |
indexEnd: {}, | |
pageRecs: {}, | |
totalRecs: {} | |
} | |
}); | |
var myAccountResults = new AccountList({model:Accounts}); | |
var cols = [ | |
{ key: "sf_account_id", label: "SF Account ID" }, | |
{ key: "account_name", label: "Account Name" }, | |
{ key: "account_owner_id", label: "Owner ID"}, | |
{ key: "contact_city", label: "City" }, | |
{ key: "contact_state", label: "State" }, | |
{ key: "contact_phone", label: "Phone" } | |
]; | |
Y.Global.on('parsed', function(e) { | |
Y.log(e.results, 'info', 'parsedEvent'); | |
}); | |
var dtable = new Y.DataTable({ | |
columns: cols, | |
data: myAccountResults, | |
scrollable: 'y', | |
sortable: true, | |
width: '880px', | |
height: '265px', | |
sortBy: [ { account_name:'asc' }], | |
paginator: new Y.PaginatorView({ | |
model: new Y.PaginatorModel({page:1, itemsPerPage:20}), | |
container: Y.one('#pagContainerBar'), | |
paginatorTemplate: Y.one('#tmpl-bar'), | |
paginatorResize: true, | |
pageOptions: [ 10, 20, 50 ] | |
}) | |
}).render(viewPane); | |
dtable.data.load({ | |
startIndex: 0, | |
numRecs: 20, | |
sortBy: dtable.get('sortBy') | |
}); | |
}, Y); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment