简体   繁体   English

Ag-Grid - 如何为最后一行设置边框底部

[英]Ag-Grid - How to Set Border Bottom for the Last Row

I am using Ag-Grid with React and I can't seem to be able to figure out how to show the border-bottom after the last row.我正在将 Ag-Grid 与 React 一起使用,但似乎无法弄清楚如何在最后一行之后显示边框底部。 The grid looks incomplete without it.没有它,网格看起来不完整。 See the attached image.请参阅随附的图像。 Need the border bottom after the last row最后一行后需要边框底部

I tried to set the following CSS, but it doesn't work:我试图设置以下 CSS,但它不起作用:

.ag-footer-cell-entire-row {
    border-bottom: solid 1px black !important;
}

In the documentation, I also looked at the rowStyle property and tried to use it but I can't figure out how to determine if the current row is the last row.在文档中,我还查看了rowStyle属性并尝试使用它,但我无法弄清楚如何确定当前行是否是最后一行。 I will greatly appreciate if someone could point me in the right direction.如果有人能指出我正确的方向,我将不胜感激。

Using rowStyle is really close... You will actually need to use getRowStyle which you will need to return an object of CSS values per the docs .使用rowStyle非常接近......您实际上需要使用getRowStyle ,您需要根据docs返回一个 CSS 值对象。 Here is an example of what your function will look like:以下是您的函数外观示例:

gridOptions = {
    ...
    getRowStyle: lastRowBorder
    ...
}

function lastRowBorder(params){
    if (params.node.rowIndex == params.api.rowModel.rowsToDisplay.length - 1){
        return {border-bottom: thick green}
    }
    else {
        return {}
    }
}

I believe that this comparison params.node.rowIndex == params.api.rowModel.rowsToDisplay.length - 1 will work in all cases, but I haven't tested it myself.我相信这个比较params.node.rowIndex == params.api.rowModel.rowsToDisplay.length - 1将适用于所有情况,但我自己还没有测试过。 There is a params.api.lastChild , but I am unsure if that is only true for the last row node or if it is true for the last node for groups... which is what you seem to be doing.有一个params.api.lastChild ,但我不确定这是否仅适用于最后一行node或者是否适用于组的最后一个node ......这就是您似乎正在做的事情。 In any case it would be beneficial to console.log the params if the comparison that I provided doesn't work.在任何情况下,如果我提供的比较不起作用,那么console.log params将是有益的。


As a side note, going the route of trying to use css selectors to try to reach the last-child won't be the cleanest solution in most cases since ag grid relies on absolute positioning... meaning that the last row in the grid could be in the middle of the DOM作为旁注,在大多数情况下,尝试使用 css 选择器尝试到达最后一个孩子的路线不会是最干净的解决方案,因为 ag 网格依赖于绝对定位......这意味着网格中的最后一行可能在 DOM 的中间

This is the top result when Googling "Set bottom border in agGrid".这是谷歌搜索“在 agGrid 中设置底部边框”时的最佳结果。 The issue I was having was that applying a border to the grid body was not rendering a border on the bottom of the grid (eg regardless of how man rows were present, I wanted the grid itself to have a border all the way around).我遇到的问题是,将边框应用于网格体并没有在网格底部呈现边框(例如,无论人行如何存在,我都希望网格本身始终具有边框)。 After some tinkering, here is my solution经过一些修补,这是我的解决方案

.grid-container {
    height: 70%;
    margin: 10px 20px 0 20px;

    .ag-header {
        border: 1px solid black;
        border-bottom: none;
    }

    .ag-body {
        background-color: #fdfdfd;
        border-bottom: 1px solid black;
    }

    .ag-body-viewport-wrapper {
        border: 1px solid black;
        border-top: none;
    }

    .ag-body-viewport {
        border-bottom: 1px solid black;
    }

}

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

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