Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ng-grid -> afterSelectionChange triggers twice

I have within ng-grid options:

afterSelectionChange: function (row, event) {
                console.log("Event: " + event);
                console.log("Row: " + row.rowIndex);
            },

The first time a row is selected, it works as expected. The second time, it triggers twice, once for the row leaving, and again for the new row. This is fine. The issue is, I want to take action once, for the new row. The only way I can do that is by examining the event. However the event is undefined.

Output:

Event: undefined activityGridController.js:13
Row: 0 activityGridController.js:14
Event: undefined activityGridController.js:13
Row: 1 

Question is, how to determine the new row?

like image 609
Robert Christian Avatar asked Nov 17 '13 05:11

Robert Christian


2 Answers

You could just set an extra property with the beforeSelectionChange event. Something like this

beforeSelectionChange: function(row) {
  row.changed = true;
  return true;
},
afterSelectionChange: function (row, event) {
  if (row.changed){
    console.log("deal with row " + row.rowIndex);
    row.changed=false;
  }
},
like image 152
AardVark71 Avatar answered Jan 11 '23 12:01

AardVark71


check the row.selected the first row should be false and the send row should be true.

  if(row && row.entity){
    if(row.selected){
       var selectedEntity = row.entity;
    }
  }
like image 29
Sanath Avatar answered Jan 11 '23 13:01

Sanath