Reputation: 1413
I'm using ag-grid in an anugular1 project.
I'm trying to get the 'Next' button to select the next row in my grid.
$scope.NextButtonClick = function (){
console.log("next button clicked");
var selectedNodes = $scope.gridOptions.api.getSelectedNodes();
var indexCurrentSelection = selectedNodes[0].childIndex;
I was hoping for a function like
var nextNode = MagicalStoreOfallNodes.getNodeByIndex(indexCurrentSelection + 1);
nextNode.setSelected(true, true)
But I can't find anything in the documentation https://www.ag-grid.com/javascript-grid-model/
Any help most appreciated!
Upvotes: 1
Views: 3846
Reputation: 7179
Assuming your rowSelection:'single
(I guess your question wouldnt make sense if it was 'multiple'), you can do this:
$scope.nextRecord = function () {
let selectedNodes = $scope.gridOptions.api.getSelectedNodes();
if (selectedNodes && selectedNodes.length === 1) {
let selectedNode = selectedNodes[0];
$scope.gridOptions.api.forEachNode((node) => {
if (node.childIndex === (selectedNode.childIndex + 1)) {
node.setSelected(true);
return;
}
});
}
};
But please be aware that this is a simple version of this - if you're using filtering you may need to use other versions of the forEach, or if you're using grouping you may need to check if its a parent or not and act accordingly
Upvotes: 4