如何获取vaadin-grid的行索引

时间:2018-06-26 13:42:10

标签: vaadin polymer-2.x vaadin-grid

我试图遍历vaadin-grid行以设置行样式,但是在选择行时遇到了麻烦。

<vaadin-grid id="grid" items="[[data]]">
  <vaadin-grid-column>
    <template class="header">
      <vaadin-grid-sorter path="noLine">
        <h1>Line No.</h1>
      </vaadin-grid-sorter>
    </template>
    <template>
      <p>[[item.noLine]]</p>
    </template>
</vaadin-grid-column>

...

_selectRow() {
  // Programmatically select row
}

我可以使用this.$.grid.items[arrayIndex] ...选择行数据...

如何选择一行以设置行样式?

1 个答案:

答案 0 :(得分:0)

根据吉尔伯托的建议:

<vaadin-grid-column>
   <template class="header">
     <vaadin-grid-sorter path="qty">
       <h3>Qty</h3>
       </vaadin-grid-sorter>
    </template>
  <template>
    <p style$="color: [[setCellStyle(item.qty item.qtyOther]]</p>
  </template>
</vaadin-grid-column>

...

setCellStyle(qty, qtyOther) {
  if(qty <= qtyOrder) return 'black'
  else return 'orangered'
}