Search code examples
node.jsreactjsag-gridag-grid-react

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


I need to display row index for Ag-grid table. 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. 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?

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

Solution

  • Try this:

    HTML:

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

    JS:

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

    Demo.