Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello my fellows !

Lets discuss and resolve my problem with removing a selected row in ng-grid

Lets say i have this data in my ng-grid:

JavaScript
 $scope.SelectedgridValue = []

app.controller('MyCtrl', function($scope) {
    $scope.myData().Creon3 = [{name: "Switch", id: 50},
                             {name: "Death switch", id: 43},
                             {name: "Target", id: 27},
                             {name: "Freedom", id: 29},
                             {name: "Epic", id: 34}];  
    $scope.gridOptions = { 
        data: 'myData().Creon3',
        showSelectionCheckbox: true,
         enableRowSelection: true,
         columnDefs: [{field: 'State', displayName: 'Name'}, 
                     {field:'ID',      displayName:'Id'}]
      };

//So far so good, when i select a row then i get my data inside of     //SelectedgridValues  , data is  shown like  this 
//[{"id":34,"Name":"Epic"}]



Now to delete a selected row i dont use any grid template or button witch is directly bounded to grid.

My delete function is bounded to submit function from a separated button on my view ...



Delete function is done like this :

JavaScript
 $scope.deleteSelectedRow = function () {
  angular.forEach($scope.SelectedgridValue , function (rowItem) {
 $scope.myData().Creon3.splice($scope.myData().Creon3.indexOf(rowItem.Name),1);
 });
}


And my submit function is as folows...


JavaScript
$scope.submit = function (data) {
   -- Some  code ....
   },
            function (data) {
            //call to delete function
               $scope.deleteSelectedRow()

                $route.reload();
                $scope.loadingEnd();


            });



The problem with this approach is at nothing is happening , i can't remove selected row... what is wrong ?


Please assist...

What I have tried:

See code in explanation.... WEB , WIKI , Forums , etc etc .... etc....
Posted
Updated 1-Apr-16 8:06am
v3

1 solution

JavaScript
$scope.submit = function (data) {
   -- Some  code ....
   },
            function (data) {
            //call to delete function
               $scope.deleteSelectedRow()
 
                $route.reload();
                $scope.loadingEnd();
 

            });

The problem I think is, first the function call should be within the Submit click function. Try putting the method calls inside the same Submit function block and then debug in the developer tool, to know the execution through the scope.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900