javascript - AngularJS: add/destroy detail table row -


i have angular 1.4.12 app, table created nested ng-repeat showing set of data.

<tr ng-repeat-start="item in pmt.table.data">   ...main data... </tr> <tr class="table-details" ng-repeat-end="item in pmt.table.data">     <td colspan="15">       <div uib-collapse="!item.showdetails">          <div class="table-details-content">hello world</div>       </div>      </td> </tr> 

each row has disclosure icon show additional row contains details.

in past, have loaded data , used angular ui bootstrap's "collapse" directive hide , show detail rows.

you can see entire thing in pen: https://codepen.io/smlombardi/pen/kxpqpj?editors=1010

the problem approach has become apparent when recordset has lot of data; such 1000 rows of json data. despite using one-way binding, performance slow.

what i'd rather not have detail rows included @ all, , when disclosure icon clicked, create row on fly , fetch data based on parent row id. when disclosure icon closed, destroy detail row.

i have done things jquery, i'm bit lost on how approach angular.

use ng-if.

the ngif directive removes or recreates portion of dom tree based on {expression}. if expression assigned ngif evaluates false value element removed dom, otherwise clone of element reinserted dom.

note ng-if totally creates (and destroys) new scope - want, want pay attention scope inheritance should need data binding again.

      <td colspan="15">         <!--change uib-collapse ng-if-->         <div ng-if="item.showdetails">           <div class="table-details-content">hello world</div>         </div>       </td> 

working codepen


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -