带有相关页脚按钮的 AG 网格

发布于 2025-01-11 17:39:13 字数 742 浏览 1 评论 0 原文

我正在考虑向我的 AG 网格添加页脚按钮,并希望它们与网格行相关,即我希望它们根据某些特定于行的数据启用/禁用。

我不确定这是否需要自定义实现,或者 Ag-grid 中是否有一些开箱即用的支持?

问题

class CustomPinnedRowRenderer {
  init(params) {
    this.eGui = document.createElement('div');
    this.eGui.innerHTML = `<button id='editBtn'>Edit<button> <button id='deleteBtn' disabled>Delete<button>`;

  }

After executing the line this.eGui.innerHTML, I somehow get an unnecessary/extra button element, NOT sure why...so the actual innerHTML rendered after I inspect is as below;
<button id="editBtn">Edit</button><button> </button><button id="deleteBtn" disabled="">Delete</button><button></button>

I am looking at adding footer buttons to my AG Grid and want them to be related to the grid rows i.e. I want them to be either enabled/disabled based on certain row-specific data.

I am not sure if that would require a custom implementation OR if there is some out-of-the-box support within Ag-grid ?

ISSUE

class CustomPinnedRowRenderer {
  init(params) {
    this.eGui = document.createElement('div');
    this.eGui.innerHTML = `<button id='editBtn'>Edit<button> <button id='deleteBtn' disabled>Delete<button>`;

  }

After executing the line this.eGui.innerHTML, I somehow get an unnecessary/extra button element, NOT sure why...so the actual innerHTML rendered after I inspect is as below;
<button id="editBtn">Edit</button><button> </button><button id="deleteBtn" disabled="">Delete</button><button></button>

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

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

发布评论

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

评论(1

夏末的微笑 2025-01-18 17:39:13

有几种方法可以实现这一目标:

这里的关键如下:

<AgGridReact
            // ...
            onRowSelected={(params) => {
              params.api.redrawRows({
                rowNodes: [params.api.getPinnedBottomRow(0)],
              });
            }}
            isFullWidthCell={(rowNode) => rowNode.rowPinned === 'bottom'}
            fullWidthCellRenderer={CustomPinnedRowRenderer}
            pinnedBottomRowData={[{}]}
          ></AgGridReact>
  • 我们通过提供一个空对象来添加一个空的固定底行。
  • 我还决定启用全宽行 在固定行上,这意味着单元格渲染器组件将跨越网格的整个宽度并且不使用列。如果您愿意,可以禁用此功能。
  • 当选择一行时,我们使用网格事件 onRowSelected 重绘固定行以强制其刷新,以便可以重新计算禁用按钮的逻辑。
const CustomPinnedRowRenderer = memo((props) => {
  const selectedNodes = props.api.getSelectedNodes();

  const isFirstRowSelected =
    selectedNodes.filter((node) => node.rowIndex === 0).length > 0;
  return (
    <button disabled={isFirstRowSelected}>
      enabled only if first row is selected
    </button>
  );
});

请参阅下面的实现 Plunkr

There's a few ways of achieving this:

The key here is the following:

<AgGridReact
            // ...
            onRowSelected={(params) => {
              params.api.redrawRows({
                rowNodes: [params.api.getPinnedBottomRow(0)],
              });
            }}
            isFullWidthCell={(rowNode) => rowNode.rowPinned === 'bottom'}
            fullWidthCellRenderer={CustomPinnedRowRenderer}
            pinnedBottomRowData={[{}]}
          ></AgGridReact>
  • We are adding an empty pinned bottom row by providing an empty object.
  • I've also decided to enable Full Width Rows on the pinned row, meaning that the cell renderer component will span the entire width of the grid and not use columns. You can disable this if you wish.
  • When a row is selected, we redraw the pinned row to force it to refresh using the grid event onRowSelected, so that the logic to disable the button can be recomputed
const CustomPinnedRowRenderer = memo((props) => {
  const selectedNodes = props.api.getSelectedNodes();

  const isFirstRowSelected =
    selectedNodes.filter((node) => node.rowIndex === 0).length > 0;
  return (
    <button disabled={isFirstRowSelected}>
      enabled only if first row is selected
    </button>
  );
});

See this implemented in the following Plunkr

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