Created
February 16, 2015 23:00
-
-
Save rebolyte/b0d742b72fc9c3f9765a to your computer and use it in GitHub Desktop.
access nested data in dgrid
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
| // 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