vaadin / vaadin-grid

vaadin-grid is a free, high quality data grid / data table Web Component. Part of the Vaadin components.
https://vaadin.com/components
Apache License 2.0
399 stars 155 forks source link

Computed binding parameter in row is undefined v3.0.0-beta1, polymer2 #921

Closed iceflow19 closed 4 years ago

iceflow19 commented 7 years ago

Hi, computed data bindings in rows are not evaluating properly. Parameters (like id) come in as undefined when the _computeRole is evaluated.

<dom-module id="trz-users-view">
  <template>
    <trz-users-model id="model" data="{{users}}" mock></trz-users-model>
    <!-- users.roles = [{id: 0, name: "Admin"}, etc...] -->

    <vaadin-grid class="flex-1" id="material" items="[[users.items]]">
      <vaadin-grid-column-group>
        <template class="header">
        </template>

        <vaadin-grid-selection-column></vaadin-grid-selection-column>
        <vaadin-grid-column  width="50px">
          <template class="header">
            <vaadin-grid-sorter  path="role">
              Role
            </vaadin-grid-sorter>
          </template>
          <template>
            <div class="bodycell">[[_computeRole(item.roleID)]]</div>
          </template>
        </vaadin-grid-column>
      </vaadin-grid-column-group>
    </vaadin-grid>
  </template>
  <script>
    class TRZUsersView extends Polymer.Element {
      static get is() { return 'trz-users-view'; }

      static get properties() {
        return {
          users: {
            type: Object,
            notify: true
          }
        };
      }

      _computeRole(id){
         var temp = this.users.roles.filter(function(val){
            return val.id == id;
          });
          if (temp.length == 0){
            return "";
          } else {
            return temp[0].name;
          }
      }
    }

    window.customElements.define(TRZUsersView.is, TRZUsersView);
  </script>
</dom-module>
web-padawan commented 4 years ago

The original issue was probably caused by the fact that computed function didn't take all the arguments it needs - it would be better to use [[_computeRole(item.roleID, users.*)]].

We no longer support vaadin-grid version 3, and now it is very outdated. It is recommended to use the most recent version (currently 5.x) which gets all the fixes.

There hasn't been any activity in this issue for a while. Closing as stale.