I have a html table whose table data are connected to an array having bunch of objects (ex:{key:abc,value:100},{key:ac,value:200}). I am using angularjs and with the aid of ng-repeat directive I populate my table data with this array. Also I have one more functionality in the application, there is a dropdown and when a user selects an item from this drop down it gets pushed to my array of objects and since array is binded to my table so table gets dynamically updated. Similar is the procedure for deletion. Now, my question is user only add or removes a single item at a time and due to change in model whole table is re-rendered from scratch though I need addition/deletion of just one row. I mean I need diff of past state and current state to be appended but actually I am re-rendering whole table which is computationally very expensive. Is there a way I can avoid it? As I said I am using Angular. I havent used React from facebook but I read somewhere it works on a similar concepts of diffs.
Here is some code: Table in HTML file connected to selectedProducts array.
<table class="table table-condensed table-bordered table-striped" ng-show="selectedProducts.length>0">
Dropdown present in HTML file which adds selected item to selectedProducts array.
<select id='select_product' class='form-control' ng-model="selected_product" ng-options="product.key for product in products" ng-change="selectedProducts.push(selected_product)"></select>
This is how table rows are genereated:
<tr ng-repeat="selected_product in selectedProducts track by $index">
<td>{{selected_product.key}}</td>
<td>{{selected_product.value}}</td>
<td><a href ng-click="selectedProducts.splice($index, 1)">X</a></td>
</tr>
Array defined in the js file:
$scope.selectedProducts = [];