如何按行明智地在Ag-grid中添加特定的组件(例如输入组件),或者如何在Ag-grid中按行删除组件?

时间:2019-05-27 04:37:21

标签: ag-grid

如何在特定行中添加特定组件(如Checkbox,Input,select,下拉组件)?每当我将组件添加到列中时,它就会出现在每一行中。如何从特定行中删除组件?

您可以在链接的图像中看到作为参考,我不需要最后4个选择组件,但是我需要将这些行留为空白: https://imgur.com/v3ktlq1

 this.columnDefs1=[ 
    {
     headerName: "M1",
     field: "m1",
     width: 90,
     cellRendererFramework: InputComponent,
     controlData: {
       type: 'text'
          },
},
]

this.rowData1 = [
    { 
    m1:"50",
},
{ 
    m1:"30",
},
{ 
    m1:"",     //If I don't want input component in this row,how can i remove? 
                 i have tried by not giving m1 also but its coming in whole 
                 column or every row.
},
{ 
    m1:"20",
},
]

1 个答案:

答案 0 :(得分:0)

您可以使用colDef.cellRendererSelector,该功能可以根据行数据选择渲染器

headerName: "M1",
field: "m1",
width: 90,
cellRendererSelector: function (params) { 
  if (params.data.m1) {
    return InputComponent;
  } else {
    return null;
  }
},
controlData: {
    type: 'text'
}

您可以在此处详细了解-https://www.ag-grid.com/javascript-grid-cell-rendering/#many-renderers-one-column