0

I have the data table and when I select a radio button, the entire table row gets selected. below is my code

enter image description here

Expectation:

When I select the radio button it should not select the table row. Demo could someone help me on this

  <md-data-table-container>
               <table md-data-table md-row-select="testConfig.selected">
                  <thead md-trim-column-names md-order="testConfig.order">
                     <tr>
                        <th order-by="name">Report Name</th>
                        <th numeric order-by="views.value">Visits</th>
                        <th numeric order-by="users.value">Unique Users</th>
                        <th>Users</th>
                     </tr>
                  </thead>
                  <tbody md-auto-select>
                     <tr ng-repeat="report in test_data | orderBy: testConfig.order">
                        <td>{{report.name}}</td>
                        <td>{{report.views.value}}</td>
                        <td>{{report.users.value}}</td>
                        <td>
                           <ul>
                              <li ng-repeat="person in people">
                                 <label>
                                 <input type="radio" ng-model="$parent.name" name="name" value="{{person.name}}" required />{{person.name}}
                                 </label>
                              </li>
                           </ul>
                        </td>
                     </tr>
                  </tbody>
               </table>
            </md-data-table-container>

1 Answer 1

1

Use Event.stopPropagation on label of radio button, to prevent the click event propagation to the table row:

<md-data-table-container>
   <table md-data-table md-row-select="testConfig.selected">
      <thead md-trim-column-names md-order="testConfig.order">
         <tr>
            <th order-by="name">Report Name</th>
            <th numeric order-by="views.value">Visits</th>
            <th numeric order-by="users.value">Unique Users</th>
            <th>Users</th>
         </tr>
      </thead>
      <tbody md-auto-select>
         <tr ng-repeat="report in test_data | orderBy: testConfig.order">
            <td>{{report.name}}</td>
            <td>{{report.views.value}}</td>
            <td>{{report.users.value}}</td>
            <td>
               <ul>
                  <li ng-repeat="person in people">
                     <label ng-click="$event.stopPropagation()">
                     <input type="radio" ng-model="$parent.name" name="name" value="{{person.name}}" required />{{person.name}}
                     </label>
                  </li>
               </ul>
            </td>
         </tr>
      </tbody>
   </table>
</md-data-table-container>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.