代码之家  ›  专栏  ›  技术社区  ›  Matthew

如何获取Vaadin网格的行索引

  •  2
  • Matthew  · 技术社区  · 8 年前

    我正试着循环通过 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 回复  |  直到 8 年前
        1
  •  0
  •   Matthew    8 年前

    根据吉尔伯托的建议:

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