angularjsangularjs-scopeng-gridangular-grid

AngularJs - How to get cell data of clicked row


I have created an Angular Js ui-grid, and last column consist with a button. when click on that button i need to get the data of each cell of that row. if anyone can help me to figure this out would be appreciate.

var removeTemplate = '<input type="button" value=""  style="background: url(../../Content/images/del-currency.png);widht:60px;height:30px"  ng-click="removeRow()" />';
    $scope.selectedCurrencyGrid = {
                    data: 'selectedCurrencies',
                    multiSelect: false,
                    selectedItems: $scope.selectedCurrencyRow,
                    enableColumnResize: false,
                    enableRowSelection: true,
                    columnDefs: [
                          { field: 'Name', displayName: 'Name' },
                          {
                              field: 'IsDefault',
                              displayName: 'Default',
                              cellTemplate: '<input type="radio" name="radAnswer" ng-model="row.entity.IsDefault">'
                          },
                          { name: 'Photo', field: 'photoP', displayName: '', cellTemplate: removeTemplate }
                    ]

                };


$scope.removeRow = function () {
            var index = this.row.rowIndex;
            //need to get cell data of selected row
        };

enter image description here


Solution

  • Add row.entity to your template function,
    this will give you access to the object properties (row cells):

    <input type="button" value="" style="background: url(../../Content/images/del currency.png);widht:60px;height:30px" ng-click="removeRow(row.entity)" />';

    Make sure your function in the conteroller gets a parameter:

    $scope.removeRow = function (selectedRowObject) {
                //Your logic...
            };