AG网格头部框架FRAMEWORK PROP不渲染自定义组件

发布于 2025-02-08 10:34:43 字数 1281 浏览 2 评论 0 原文

我正在尝试使用AG网格创建自定义标头并进行反应,但无法在我的 HeaderComponentFramework prop中渲染自定义组件 prop autogroupcolumpcolumndefs 。

ag noreferrer“> ag grid”文档指向使用 HeaderComponentFramework ,并且在使用其plunker链接编辑其示例代码时,我可以成功地创建和编辑自定义标题。当我尝试在代码中实现相同的内容时,我甚至无法访问组件。例如,我试图委托。从我的自定义标头组件中删除一条消息,但没有登录。我还尝试了替代道具,例如 HeaderComponent headerGroupComponent ,但它们也没有起作用。

下面的示例代码:

import CustomHeaderComponent from './filePath';

autoGroupColumnDef = useMemo(() => {
  headerComponentFramework: CustomHeaderComponent
  headerName: ‘name’,
  suppressMenu: true,
  cellRendererSelector: () => {}
  pinned: left,
}), [dependencies])

gridOptions = { 
  …otherGridOptions,
  autoGroupColumnDefs
}

return (
  <AgGridComponent 
    gridOptions={gridOptions}
  />
)

export const CustomHeaderComponent = {
  console.log(‘hello world’); // doesn't log

  // do stuff 

  return (
    <div> {Custom Header} </div>
  )
}

HeaderComponentFramework 在此处使用的正确道具吗?如果有人对如何渲染自定义标题有建议,将不胜感激。请让我知道我是否也可以提供其他详细信息。

I am attempting to create a custom header using AG Grid and React, but am unable to render the custom component that is passed into the headerComponentFramework prop within my autoGroupColumnDefs.

The AG Grid documentation points to using headerComponentFramework, and when editing their example code with their Plunker link I am successfully able to create and edit a custom header. When I attempt to implement the same thing in my code, I'm not able to even access my component. E.g. I tried to console.log a message from my custom header component, but it didn't log. I also tried alternate props, such as headerComponent and headerGroupComponent but those didn't work either.

Sample code below:

import CustomHeaderComponent from './filePath';

autoGroupColumnDef = useMemo(() => {
  headerComponentFramework: CustomHeaderComponent
  headerName: ‘name’,
  suppressMenu: true,
  cellRendererSelector: () => {}
  pinned: left,
}), [dependencies])

gridOptions = { 
  …otherGridOptions,
  autoGroupColumnDefs
}

return (
  <AgGridComponent 
    gridOptions={gridOptions}
  />
)

export const CustomHeaderComponent = {
  console.log(‘hello world’); // doesn't log

  // do stuff 

  return (
    <div> {Custom Header} </div>
  )
}

Is headerComponentFramework the correct prop to use here? If anyone has suggestions on how to render a custom header, it would be greatly appreciated. Please let me know if I can provide additional details as well.

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

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

发布评论

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

评论(2

少女七分熟 2025-02-15 10:34:43

我成功地使用了 HeaderComponent ,并在 frameworkComponents prop中注册我的组件:

autoGroupColumnDef = useMemo(() => {
  headerComponent: 'customHeaderComponent'
  headerName: ‘name’,
  suppressMenu: true,
  cellRendererSelector: () => {}
  pinned: left,
}), [dependencies])

gridOptions = {
  …otherGridOptions,
  frameworkComponents: {
    customerHeaderComponent: CustomHeaderComponent
  },
  autoGroupColumnDefs
}

我仍然不确定为什么 HeaderComponentFramework 不起作用。

I was successful in using headerComponent and registering my component in the frameworkComponents prop:

autoGroupColumnDef = useMemo(() => {
  headerComponent: 'customHeaderComponent'
  headerName: ‘name’,
  suppressMenu: true,
  cellRendererSelector: () => {}
  pinned: left,
}), [dependencies])

gridOptions = {
  …otherGridOptions,
  frameworkComponents: {
    customerHeaderComponent: CustomHeaderComponent
  },
  autoGroupColumnDefs
}

I'm still not sure why headerComponentFramework isn't working.

筑梦 2025-02-15 10:34:43

在我的情况下,我使用了AG版本26.2.0使用with react 18-而不是给出任何错误,它只是跳过呈现标头组件并在列标题中渲染的任何内容:请参见此stackblitz 进行复制。

升级到AG版本27+修复了它。

In my case I had AG version 26.2.0 using with React 18 - instead of giving out any errors, it just skips rendering the header component and render nothing in the column headers: see this stackblitz for a reproduction.

Upgrade to AG version 27+ fixes it.

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