Skip to content

Instantly share code, notes, and snippets.

@rebolyte
Created February 16, 2015 23:00
Show Gist options
  • Select an option

  • Save rebolyte/b0d742b72fc9c3f9765a to your computer and use it in GitHub Desktop.

Select an option

Save rebolyte/b0d742b72fc9c3f9765a to your computer and use it in GitHub Desktop.
access nested data in dgrid
// http://dgrid.io/js/dgrid/test/Grid_rendering.html
// Apparently this is the only way to access nested data? And it's
// seriously legacy and only supported because of old DojoX stuff?
// data format goes thusly:
// {
// "_id": 1,
// "name": {
// "formatted": "first last",
// "last": "last",
// "first": "first"
// },
// "organization": {
// "name": "name"
// },
// "address": {
// "formatted": "street^/city, ST 23455",
// "street": "street",
// "city": "city",
// "state": "ST",
// "zip": "23455"
// }
// }
var TrackableMemory = declare([ Memory, Trackable ]);
var contactMem = new TrackableMemory({
data: [],
idProperty: '_id'
});
var getCon = {
last: function (item) {
return item.name.last;
},
first: function (item) {
return item.name.first;
},
org: function (item) {
return item.organization.name;
},
street: function (item) {
return item.address.street;
},
city: function (item) {
return item.address.city;
},
state: function (item) {
return item.address.state;
},
zip: function (item) {
return item.address.zip;
}
}
var contactsGrid = new OnDemandGrid({
collection: contactMem,
columns: {
last: {
label: 'Last',
get: getCon.last
},
first: {
label: 'First',
get: getCon.first
},
organization: {
label: 'Organization',
get: getCon.org
},
street: {
label: 'Street',
get: getCon.street
},
city: {
label: 'City',
get: getCon.city
},
state: {
label: 'State',
get: getCon.state
},
zip: {
label: 'Zip',
get: getCon.zip
}
},
className: 'dgrid-autoheight',
noDataMessage: 'No records found'
}, 'contactsGrid');
contactsGrid.startup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment