Cannot get selected rows using Angular UI Grid

I have two grids that have rows that I can select. I want to be able to get the data in the selected rows to another data object so that I can pass it to the backend service. Here is the relevant code:

angular.module('gridPanel',['ui.bootstrap','ui.grid', 'ui.grid.edit', 'ui.grid.rowEdit', 'ui.grid.cellNav', 'ui.grid.selection'])
.controller('GridPanelController', function($scope, $log, referenceDataService){

    $scope.nameGrid = {
        enableRowSelection: true,
        enableRowHeaderSelection: false,
        multiSelect: true,
        onRegisterApi: function(gridApi) {
            $scope.gridApiNames= gridApi;
        },
        columnDefs: [
            {name: 'Name', field: 'name'}
            {name: 'Description', field: 'description'}
        ],
        data:[]
    };

    $scope.regionsGrid = {
        enableRowSelection: true,
        enableRowHeaderSelection: false,
        multiSelect: true,
        onRegisterApi: function(gridApi) {
            $scope.gridApiRegions = gridApi;
        },
        columnDefs: [
            {name: 'Region', field: 'region'}
        ],
        data:[]
    };

    referenceDataService.getAllNames().then(function (data){
        $scope.nameGrid.data = data;
    });

    referenceDataService.getRegions().then(function (data){
        $scope.regionsGrid.data = data;
    });

    $scope.debug = function(obj) {
        var dataObj = {
            names: [],
            regions: []
        };

        dataObj.regions = $scope.gridApiRegions.selection.getSelectedRows();
        dataObj.names= $scope.gridApiNames.selection.getSelectedRows();

        $log.log(JSON.stringify(dataObj, null, 4));
    };
});

, , , , dataObj.regions dataObj.names - . , - . , , $scope.debug, . , , , , - . !

edit: , 'getSelectedRows', .

+4
1

. , - ( ) . , . , , , , - - ?

+2

Source: https://habr.com/ru/post/1611803/


All Articles