简体   繁体   中英

React ag grid conditional cellrenderer

I want the props cellRenderer: 'agGroupCellRenderer' work conditionally. ex,

{
      headerName: 'testname',
      valueGetter: params => {
        return .....;
      },
      cellRenderer: 'agGroupCellRenderer',
      cellRendererParams: {
        suppressCount: true,
      },
}

if params.data.type==='group', then cellRenderer: 'agGroupCellRenderer', otherwise, cellRenderer:''(just do not render it as group).

I did something like

cellRenderer: params => {
        return params.data.group=== 'Y' ? cellRenderer:'agGroupCellRenderer' : '';
      },

but it just returns the string 'agGroupCellRenderer'

You have defined your own cellRender function, so the AG-Grid will use the value you returned.

Maybe you can do something like this

cellRenderer: params => {
    params.data.group=== 'Y' ? cellRenderer: params.colDef.cellRenderer = 'agGroupCellRenderer' : '';
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM