ag-grid: Need to aggregate multiple fields into a table within a cell

我怕爱的太早我们不能终老 提交于 2020-01-06 06:52:36

问题


I'm wondering what the best practice is for displaying a table (with data from multiple fields) within a cell in ag-grid?

I think I can get it to work with formatting the entire table as an html string and passing that to the grid as the field and using a cellRenderer, however I'd rather not have that kind of view logic on the server-side.

I'd really like for the column definition to be able to take in more than one field, but it doesn't seem like that's possible.

Any ideas? Thanks.


回答1:


You can define a valueGetter for the desired column in column def. Here is a sample -

valueGetter: 
function sumField(params) {
          return params.data.a + params.data.b
}

Value getters example




回答2:


In your ColDef for the column, you can pass data and then destructure the values you're looking for off of that object, which comes through props in ag-grid.

For example...

In your ColDef array:

{
  field: 'data',
  headerName: 'Name',
  cellRendererFramework: NameDescriptionRenderer
}

Then, in your NameDescriptionRenderer:

export default class NameDescriptionRenderer extends React.Component {
  public render() {
    const { description, name } = this.props.data;
    return <React.Fragment>{`${name}: ${description}`}</React.Fragment>;
  }
}


来源:https://stackoverflow.com/questions/50866364/ag-grid-need-to-aggregate-multiple-fields-into-a-table-within-a-cell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!