Search code examples
ag-gridag-grid-angular

How to focus on a particular row in agGrid(angular),If only the unique data in that particular row is only known?


I have an agGrid with some data having two rows as unique key: id, name, address, status These are my columns where name and status is unique. How can i focus on a particular row on page reload if i have a name and status known.

I tried to get the rowIndex for that particular row, But rowId for that row is not getting.

this.gridOptions.getRowNodeId = function(data) {
  return data.id
};
var rowNode = this.gridOptions.api.getRowNode('x');
rowNode.setSelected(true);

How i will get this data.id and x with only name and status value known ?

Please help me to find the solution. Thank you in advance.


Solution

  • You are doing it correctly, but since you dont know the id while retrieving the rowNode back, it will be useful to define a key with name+status since that is unique as well.

    First of all, you need to provide getRowNodeId() to your grid.

    Since name + status combination is unique, I am telling grid to use that as a key

    gridOptions.getRowNodeId = function(data) {
        return data.name + '_' + data.status;
    };
    

    Now since you have known values of name and status, I would just do

    var rowNode = this.gridOptions.api.getRowNode("name_status"); //pass your known name_status
    
    rowNode.setSelected(true);