Skip to content

Instantly share code, notes, and snippets.

@kzahel
Created February 23, 2016 22:51
Show Gist options
  • Save kzahel/5b86054e42a9ecd898fc to your computer and use it in GitHub Desktop.
Save kzahel/5b86054e42a9ecd898fc to your computer and use it in GitHub Desktop.
<dom-module id="my-table">
<template>
<!--iron-list items="[[items]]" as="item">
<template>
<div>
Name: [[item.name.first]]
</div>
</template>
</iron-list--> <!-- this will re-render correctly when items are added -->
<iron-data-table items="[[items]]">
<data-table-column name="First Name" sort-by="name.first">
<template>[[ item.name.first ]]</template>
</data-table-column>
<data-table-column name="Last Name" sort-by="name.last">
<template>[[ item.name.last ]]</template>
</data-table-column>
<data-table-column name="Title" sort-by="name.title">
<template>[[ item.name.title ]]</template>
</data-table-column>
</iron-data-table>
</template>
</dom-module>
<my-table></my-table>
Polymer({
is: 'my-table',
observers: [
'usersAddedOrRemoved(items.splices)'
],
properties: {
items: {type:Array,
value:[],
notify:true}
},
usersAddedOrRemoved: function(splices) {
console.log('users added or removed',splices)
},
addUser: function(user) {
this.push('items', user)
},
ready: function() {
console.log('my-table ready')
this.addUser({name:{first:"bob",last:"smith",title:'mr'}})
this.addUser({name:{first:"dan",last:"smith",title:'mr'}})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment