Gregory Sieranski
Gregory Sieranski

Reputation: 23

Ag Grid Prevent Column from changing during sort

I have the following Column definition

<AgGridColumn headerName="Rank" cellRendererFramework={NodeIDRenderer} suppressFilter={true} suppressSorting={true} lockPosition/>

And the Cell renderer it's using is this

import React from 'react';

class NodeIDRenderer extends React.Component {

  render() {

    return (
      <div>{Number(this.props.node.id) + 1}</div>
    );
  }
}

export default NodeIDRenderer;

What I am trying to do is have this Column be a way to Rank other Columns when they are sorted. So I want this Column to always start a 1 and go to N. The issue I am facing is that when I sort any of my other columns this Rank column also changes. Is there a way to "lock" the column so the data never moves?

Upvotes: 2

Views: 833

Answers (1)

Jarod Moser
Jarod Moser

Reputation: 7338

Use the node.rowIndex rather than the node.id. The id gets set once to maintain a unique reference to the node, the index is updated on any sort or filter. I did notice that the filter had a tendency to be a little unreliable with the row, so I called the refreshCells function of the grid api when the filter was updated. Here is a plunker you can test with.

Upvotes: 2

Related Questions