Saulis / iron-data-table

iron-data-table is a Web Component for displaying data as a table or grid. Built on top of iron-list using Polymer.
Apache License 2.0
147 stars 65 forks source link

Using row item as param for function call #137

Closed hankphung closed 8 years ago

hankphung commented 8 years ago

I pass item as param like this and got error item not defined

  <data-table-column name="Title">
    <template>[[item.title]]</template>
  </data-table-column>

  <data-table-column name="Price">
    <template>[[item.price]]</template>
  </data-table-column>

  <data-table-column name="Action">

   <template>

     <paper-button onclick="_edit(item)">   E </paper-button>

   </template>

  </data-table-column>

```

web-padawan commented 8 years ago

First, you should use on-tap (Polymer listeners) instead of onclick (plain JS). And another thing: you cannot pass item like this when using Polymer listeners, so the correct syntax is:

<paper-button on-tap="_onItemTap">   E </paper-button>

Then, pay attention to e.model inside of the listener:

  _onItemTap: function (e) {
    console.log('Title: ' + e.model.item.title);
  }

The same approach works for dom-repeat templates as well.

hankphung commented 8 years ago

@web-padawan Thank you, it work now. This gonna help when put in the element demos.