简体   繁体   English

如何在 Ag-Grid 中以相反方向显示行索引?

[英]How to display row index in Ag-Grid in opposite dirrection?

I need to display row index for Ag-grid table.我需要显示 Ag-grid 表的行索引。 My problem is that it numerates first item on the top of grid as Nr 1. But i need ag grid to numerate first item with larges number and item at the bottom oldest one with Nr 1. I was looking a lot on documentation, but havent found any smart solution.我的问题是它将网格顶部的第一个项目计算为 Nr 1。但我需要 ag 网格来计算第一个具有大号的项目和底部最旧的项目与 Nr 1。我在文档上看了很多,但还没有找到了任何聪明的解决方案。 I could write my own cell renderer here but i think it would be wrong and complicated way of doing so.我可以在这里编写自己的单元格渲染器,但我认为这样做是错误且复杂的。 Does anyone knows is it possible to do something with value getter to make it count in opposite direction?有谁知道是否可以用 value getter 做一些事情来使它在相反的方向计数?

<AgGridColumn
  headerName={'Nr'}
  field="i"
  width={50}
  lockPosition={true}
  valueGetter='node.rowIndex+1' 
/> 

Try this:尝试这个:

HTML: HTML:

<AgGridColumn
          headerName={'Nr'}
          field="i"
          width={50}
          lockPosition={true}
          valueGetter={inverseRowCount}
        />

JS: JS:

const inverseRowCount = (params) => {
    return params.api.getDisplayedRowCount() - params.node.rowIndex;
  };

Demo . 演示

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

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