How do I set row selection for a newly added row?

I need to set the selection to a newly added row. When entered $scope.gridApi.selection.selectRow(newObject)

, the grid row model does not have a new row and therefore cannot select one. When the method completes, the addRow

grid shows a new row (and data), but no selection has been made.

My test code:

$scope.addRow = function() {
    $scope.gridOptions.data.unshift({
        // my new data object
    });

    var newObject = $scope.gridOptions.data[0];
    $scope.gridApi.selection.selectRow(newObject);
};

      

How can I achieve this behavior?

Is there an event like "rowAdded" in angularjs ui-grid that I should be listening to? Is there an exhaustive list of events fired with ui-grid somewhere?

Thanks for the help!

+3


source to share


1 answer


You can listen for events on row, column and so on. The documentation is here http://ui-grid.info/docs/#/api/ui.grid.class:Grid

You can add a data listener to onRegisterApi as shown below,

onRegisterApi : function(gridApi)
            {
                if(!$scope.gridApi) 
                {
                    $scope.gridApi = gridApi; 
                    $scope.gridApi.grid.registerDataChangeCallback(function(data)
                    {
                      $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
                    }, [uiGridConstants.dataChange.ROW]);
                }
            }

      



and select any line you want to select.

Here is a working plnkr. http://plnkr.co/edit/NjnMb65w86L0bKmkkJp0?p=preview

+4


source







All Articles