2

I currently have a grid that I created with Angular ui-grid that allows the user to select a number of rows. The first column of each row has an id number, and I would like to add the ids of the selected rows to an object in my model so that I can use those ids to query my database on the back end.

My problem is that I have not figured out how to access cell values, much less how to add the value of selected cells to my model. So any help would be very much appreciated!

Here is the code for my grid that I use in my controller

        $scope.gridOptions = {
        enablePaginationControls: false,
        enableRowSelection: true,
        enableSelectAll: true,
        paginationPageSize: 25,
        enableHorizontalScrollbar: 0,
        enableVerticalScrollbar: 0,
        columnDefs: [
            {field: 'analysis_id',displayName: 'Analysis ID',width: '15%'}, 
            {field: 'study_id', displayName: 'Study ID',width: '15%'},
            {field: 'publisher', displayName: 'Publisher',cellFilter: 'titlecase',width: '20%'},
            {field: 'parent_company', displayName: 'Parent Company', cellFilter: 'titlecase',width: '30%'}
        ]};

    $scope.gridOptions.onRegisterApi = function(gridApi) {
        $scope.gridApi = gridApi;
    };

2 Answers 2

1

Try

$scope.gridApi.cellNav.on.navigate($scope,function(newRowCol, oldRowCol) {               
    console.log($scope.gridApi.grid.getCellValue(newRowCol.row,newRowCol.col));
});
Sign up to request clarification or add additional context in comments.

2 Comments

I tried to add this, but it broke my controller with the following error TypeError: Cannot read property 'cellNav' of undefined
@dsal1951, its to put inside onRegisterApi, after you assign $scope.gridApi
1

Maybe gridApi.selection.getSelectedRows(); is something you need.

( ['ui.grid.selection'] dependence in app.module required)

$scope.gridOptions.onRegisterApi = function(gridApi){

    $scope.gridApi = gridApi;
    gridApi.selection.on.rowSelectionChanged($scope,function(row){
        $scope.selectedObject = gridApi.selection.getSelectedRows();
        console.log ($scope.selectedObject);
    });
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.