0

I have the following table:

<table>
    <tr data-ng-repeat-start=... data-ng-click="contactGroup.expanded = !contactGroup.expanded">
         <td class="myColumn" data-ng-click=...> 

when a row is clicked than the row expands and additional information is shown to this row - this works fine. In this row there is also a column (myColumn) which can be clicked. If this column is clicked than first the row expands and than the proper click event is handled. Is there a way to prevent the expandation of the row when the column myColumn is clicked?

3 Answers 3

1

The reason it is happening because of event bubbling and to stop it event.stopPropogation() can be used.

While clicking the column bind a method; and use $event to prevent default

<table>
    <tr data-ng-repeat-start=... data-ng-click="contactGroup.expanded = !contactGroup.expanded">
         <td class="myColumn" data-ng-click="toggleColumn($event)"> 

And in Controller:

$scope.toggleColumn = function(e){
    e.stopPropogation(); //This would prevent event bubbling from td to tr
    e.preventDefault(); //This will prevent default action like link load on click of hyperlink
    //toggle functionality
}
Sign up to request clarification or add additional context in comments.

Comments

0

You need to bind the row click event in column and remove from the row.

Please check the bellow.

<table>
    <tr data-ng-repeat-start=... data-ng-click="">
         <td class="myColumn" data-ng-click="contactGroup.expanded = !contactGroup.expanded; <columnClickEventHandl>"> 

Comments

0

try

<table>
  <tr data-ng-repeat-start=... 
      ng-click="!contactGroup.expanded && contactGroup.expanded = !contactGroup.expanded">
     <td class="myColumn" ng-click=...> 

note, that assignment in the row's ng-click's expression will be executed only when contactGroup.expanded is false

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.