将动态参数传递给父部件中的单元渲染器(Ag网格)

发布于 2025-02-09 08:43:43 字数 316 浏览 1 评论 0原文

如何基于单元格参数传递动态参数? 像这里一样,当我们基于单元格参数添加类时,

cellClassRules: {
   'error-border': (params: any) => {
      return params.error;
    },
},

我想使用CellRendererParams进行相同的操作,但它不起作用:

cellRendererParams: {
  someProp: (params: any) => {
    return ...;
  },
},

How to pass dynamic params based on cell params?
Like here when we adding class based on cell params

cellClassRules: {
   'error-border': (params: any) => {
      return params.error;
    },
},

I want to do the same with cellRendererParams but it not working:

cellRendererParams: {
  someProp: (params: any) => {
    return ...;
  },
},

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉月流沐 2025-02-16 08:43:43

说我有一个自定义的单元格渲染器。它具有我要设置的属性称为myprop的属性:

export class MyCellRendererComponent implements ICellRendererAngularComp {

  params: any;
  myProp = true;
}

在我要使用的组件中,我必须将其添加到组件列表中:

<ag-grid [components]="components" >

components = {
    myCellRenderer: MyCellRendererComponent
  };

然后,当我设置列时,我可以指定单元格渲染器并设置MyProp属性,例如这:

{
  field: 'myField',
  width: 150,
  cellRenderer: 'myCellRenderer',
  cellRendererParams: {
    myProp: (params) => {
      console.log(params.data.myPropValue); // <-- Can you try this?
      return params.data.myPropValue;
    }
  }
}

您的自定义组件肯定是使用的吗?设置自定义属性时,可以放置台。

让我知道你的状况

Say I have a custom cell renderer. It has a property called myProp that I want to set:

export class MyCellRendererComponent implements ICellRendererAngularComp {

  params: any;
  myProp = true;
}

In the component I want to use it I have to add it to the list of components:

<ag-grid [components]="components" >

components = {
    myCellRenderer: MyCellRendererComponent
  };

Then when I set up my columns I can specify the cell renderer and set the myProp property like this:

{
  field: 'myField',
  width: 150,
  cellRenderer: 'myCellRenderer',
  cellRendererParams: {
    myProp: (params) => {
      console.log(params.data.myPropValue); // <-- Can you try this?
      return params.data.myPropValue;
    }
  }
}

Is your custom component definitely being used? Can you put a console.log when you are setting your custom property?

Let me know how you get on

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文