How to get custom values for each richSelect in ag-grid

811 views Asked by At

I have ag-grid reach based application where richSelect dropdowns are being used for certain columns. For some of richSelect columns, values in the dropdown should be based on an id.

My JSON data would look like this:

data : [{
        collegeId : "MIT",
        users : [{
                name : "Alex",
                country : "USA"
            }, {
                name : "Barbara",
                country : "Canada"
            }
        ]
    }, {
        collegeId : "Berkeley",
        users : [{
                name : "Samantha",
                country : "Australia"
            }, {
                name : "Amanda",
                country : "Germany"
            }
        ]
    }
]

Here is how my colDefs looks like:

{ headerName : "Users", field: "users", filter: "text", 
    cellEditor : "richSelect",
    cellEditorParams : {
        values : this.getValues()
    }
}

Issue is, in the row for MIT I want User list to have only Alex and Barbara. Similarly for Berkeley I need User's richSelect to only have Samantha and Amanda.

Here User list depends on collegeId. In getValues() I can fetch all the Users but don't know how to do so based on matching collegeId.

1

There are 1 answers

0
Basavaraj On

you can update value as like below--

here created $scope.newMap map, add what value to display in map with key,value and assign to cellEditorParams

 for(var x=0;x<$scope.gridOptions.columnDefs.length;x++){
            if($scope.gridOptions.columnDefs[x].headerName==="Bank Name"){
                $scope.gridOptions.columnDefs[x].cellEditorParams.values=$scope.newMap;
            }
        }