【问题标题】:How to add attribute using Ag Grid at row and cell level?如何在行和单元格级别使用 Ag Grid 添加属性?
【发布时间】:2021-11-12 09:10:21
【问题描述】:

就像我们可以使用 ag grid 添加 CSS 类一样。在 ag 网格中是否有任何方法可以在行和单元格级别添加属性。

const gridOptions = {
// all rows assigned CSS class 'my-green-class'
rowClass: 'my-green-class',

// all even rows assigned 'my-shaded-effect'
getRowClass: params => {
    if (params.node.rowIndex % 2 === 0) {
        return 'my-shaded-effect';
    }
},

// other grid options ...

例如我想像下面的“my-custom-attr="dummyValue"

<div comp-id="44" my-custom-attr="dummyValue" style="transform: translateY(0px); height: 42px;" row-index="0" aria-rowindex="2" class="ag-row-even ag-row-no-focus ag-row ag-row-level-0 ag-row-position-absolute ag-row-first" role="row" row-id="0"><div comp-id="63" class="ag-cell ag-cell-not-inline-editing ag-cell-normal-height ag-cell-value" tabindex="-1" role="gridcell" aria-colindex="2" col-id="sickDays" unselectable="on" style="left: 200px; width: 200px;">4</div></div>

【问题讨论】:

    标签: javascript ag-grid


    【解决方案1】:

    我会研究单元格渲染。 https://www.ag-grid.com/javascript-data-grid/cell-rendering/

    然后您可以通过返回将您的 attr 添加到单元格中

    return (
        <div my-attr="asdffasdf">
            {params.data.cellValue}
        </div>
    )
    

    【讨论】:

      猜你喜欢
      • 2018-07-01
      • 2020-11-16
      • 2020-11-21
      • 2021-10-03
      • 2021-02-03
      • 2021-10-21
      • 2017-01-07
      • 2017-08-31
      • 2019-02-12
      相关资源
      最近更新 更多