简体   繁体   English

将格式应用于 ag-Grid 中的行

[英]Apply formatting to a row in ag-Grid

I am using a Ag-grid and have a requirement to set the last row (kind of total) to be bold and some background.我正在使用 Ag-grid 并且需要将最后一行(总计)设置为粗体和一些背景。 How can I achieve considering that we define columns ?考虑到我们定义了列,我该如何实现? Also while the last row label (ie 1st column last row of grid) can be identified by checking params.value === 'Total', the other columns of that row can have dynamic total values (so cannot compare their actual text) Below is how the config looks like (just for one of the columns)此外,虽然可以通过检查 params.value === 'Total' 来识别最后一行标签(即网格的第一列最后一行),但该行的其他列可以具有动态总值(因此无法比较它们的实际文本)如下是配置的样子(仅针对其中一列)

   [ {
            headerName: '',
            field: 'Status',
            width:  defaultWidth,
            tooltipField:'status',
            headerTooltip: 'Status',
            sortable: false,
            resizable: false,
            cellStyle: params => {
              if (params.value === 'Total') {
                return { backgroundColor: color.orange,"font-weight":"bold" };
              } else {
                return null;
              }
            }
        }, {.....}]

You can style the last row by using the Grid Option getRowStyle :您可以使用 Grid Option getRowStyle设置最后一行的getRowStyle

  getRowStyle: (params) =>
    params.node.lastChild
      ? { backgroundColor: 'orange', 'font-weight': 'bold' }
      : null

Relevant Documentation: https://www.ag-grid.com/javascript-grid/row-styles/相关文档: https : //www.ag-grid.com/javascript-grid/row-styles/

See this implemented in the following sample: https://plnkr.co/edit/Vu32lW7jROiN0h5Q请参阅以下示例中的实现: https : //plnkr.co/edit/Vu32lW7jROiN0h5Q

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

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