Omk*_*jam 3 ag-grid ag-grid-react ag-grid-angular
在 ag-Grid 中,我想在像 Gmail 一样悬停一行时显示操作按钮。无论滚动位置如何,操作按钮都必须出现在网格的右端。
https://blog.ag-grid.com/build-email-client-with-ag-grid-like-gmail/提到了一种方法。他们在最后一列使用了 cellRenderer 并在“onCellMouseOver”发生时在其中显示按钮。只有当最后一列(使用 cellRenderer)始终在视图中时,此方法才有效。如果该列不在视图中,操作按钮也将不在视图中。
我不能使用这种方法,因为在我的情况下,有很多列,并且网格中的所有列不能同时显示在屏幕上。因此,根据滚动位置,右端可以有任何列,因此我们不知道要在哪一列上添加 cellRenderer。
我们将如何实现这一目标?
这是一个演示我的解决方案的 plunk:https : //plnkr.co/edit/X4hCimLy6aL3j4eh
事实证明,这可以仅使用 CSS 来实现。这是我如何做到的:
这是完整的 CSS 和解释:
/* Hide right header and spacer */
.ag-pinned-right-header,
.ag-horizontal-right-spacer {
width: 0 !important;
min-width: 0 !important;
}
/* Add absolute position so that action buttons column will appear on top of other columns.
pointer-events: none to pass on mouse events to behind columns */
.ag-pinned-right-cols-container {
position: absolute !important;
right: 0;
pointer-events: none;
}
/* Reset pointer-events so that click can happen on action buttons */
.ag-pinned-right-cols-container * {
pointer-events: initial;
}
/* Hide border of right-cols-container */
.ag-pinned-right-cols-container .ag-cell {
border: none !important;
}
/* Show action buttons only for the row that is being hovered.
For rows which are not being hovered, hide them by setting their width and padding to 0. */
.ag-pinned-right-cols-container .ag-row:not(.ag-row-hover),
.ag-pinned-right-cols-container .ag-row:not(.ag-row-hover) .ag-cell {
width: 0 !important;
padding: 0 !important;
}
Run Code Online (Sandbox Code Playgroud)
Ag-grid 的默认行悬停和行选择颜色具有一定的透明度。由于我们的操作按钮列绝对位于其他列之上,因此由于这些透明颜色的混合方式,其背景看起来更暗。
因此,最好在这种方法中使用不透明的背景颜色,如下所示:
.ag-theme-alpine {
--ag-row-hover-color: hsl(207, 90%, 94%);
--ag-selected-row-background-color: hsl(207, 87%, 86%);
}
Run Code Online (Sandbox Code Playgroud)
总体,
优点:-
缺点:-
| 归档时间: |
|
| 查看次数: |
2025 次 |
| 最近记录: |