Search code examples
vaadinpolymer-2.xvaadin-grid

How to get Row Index of vaadin-grid


I am trying to loop through vaadin-grid rows to set row styles, however, am having trouble selecting a row.

<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
}

I can select the row data with this.$.grid.items[arrayIndex]...

How can I select a row to set the row styling?


Solution

  • Per Gilberto's suggestion:

    <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'
    }