简体   繁体   English

ag-grid 单元格渲染器,显示来自多列的数据

[英]ag-grid cell renderer that shows data from multiple columns

I'm trying to create a cell renderer that will take data from other columns.我正在尝试创建一个单元格渲染器,它将从其他列中获取数据。

For example, each row signifies some piece of data, and users should be able to open it depending on their permissions, and a restricted piece of data should be rendered differently than a non-restricted element.例如,每一行表示一些数据,用户应该能够根据他们的权限打开它,并且受限制的数据应该与不受限制的元素呈现不同的呈现方式。 Other columns will have an affect on rendering this one column as well.其他列也会影响渲染这一列。

I would expect to be able to access the other columns' data using the path this.params.node.data.restricted , and this works during a click event, but I can't seem to have access to this data during the rendering phase of the component.我希望能够使用路径this.params.node.data.restricted访问其他列的数据,这在单击事件期间有效,但我似乎无法在渲染阶段访问这些数据组件的。

"columnDefs": [
    {
      "field": "id",
      "width": 40,
      "checkboxSelection": true
    },
    {
      "headerName": "Title",
      "field": "docTitle",
      "width": 1580,
      "cellRenderer": "detailViewRenderer"
    }
  ]
import {Component} from "@angular/core";
import {ICellRendererAngularComp} from "ag-grid-angular";

@Component({
  selector: 'detail-view-renderer',
  styles: [``],
  template: `
    <a class="restricted" *ngIf="params.node.data.restricted">{{params.value}}</a>
    <a class="not-restricted" *ngIf="!params.node.data.restricted">{{params.value}}</a>
  `
})
export class DetailViewRendererComponent implements ICellRendererAngularComp {
  public params: any;

  agInit(params: any): void {
    this.params = params;
  }

  constructor() {}

  refresh(): boolean {
    return false;
  }
}

I think ideally, what I'd like to do is set the columns that will be passed into my renderer and access them in the component somehow as parameters.我认为理想情况下,我想要做的是设置将传递到我的渲染器的列,并以某种方式在组件中访问它们作为参数。 Is that possible or do we have some other workaround?这是可能的还是我们有其他解决方法? I see Full Width Rows as an option, but that renders the entire row as one column.我将全宽行视为一个选项,但这会将整行呈现为一列。

I think you can access other row properties by using params.data.restricted , instead of params.node.data.restricted .我认为您可以使用params.data.restricted而不是params.node.data.restricted来访问其他行属性。

For example,例如,

method() {
 const detailViewRenderer = params => {
   return `<span>${params.data.restricted}</span>`;
 };


 this.columnDefs: [
    {
      "field": "id",
      "width": 40,
      "checkboxSelection": true
    },
    {
      "headerName": "Title",
      "field": "docTitle",
      "width": 1580,
      "cellRenderer": "detailViewRenderer"
    }
 ]
}

Documentation文档

如果你还在寻找答案,你可以使用rowNode.columnApi.resetColumnState()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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