suman goud

suman goud

  • NA
  • 176
  • 54k

How to add new empty row to table based on dropdown id using

Sep 29 2016 6:34 AM
When customer(dropdown) is selected am binding pending value and amount of that customer in two texboxes.
i given +(Add) to add new row to bind another customer details, am able to add new row, but in that added row same first selected
values are binding and if i change dropdown in second row,both 2 rows values are changing .
i have tried using for loop but am not getting ,
ReceiptsViewModel is to retrie data from multiple tables
<table id="myTable" class="tableData" border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Customer</th>
<th>Pendings</th>
<th>Amount</th>
<th></th>
</tr>
<tr ng-repeat="r in rvm">
<td>
<select ng-model="c" ng-change="GetAccountBalance($index,c)" ng-options="c.ID as c.Name for c in customer track by c.ID" name="tCustomer">
<option value="">Select Customer</option>
</select>
</td>
<td>
<input type="text" ng-model="ReceiptsViewModel.Pendings" name="tPendings" />
</td>
<td>
<input type="text" ng-model="ReceiptsViewModel.Pendings" name="tAmount" />
</td>
<td ng-if="$last">
<a href="#">
<span class="glyphicon glyphicon-plus orange" ng-click="addRow($index,c)"></span>
</a>
</td>
<td ng-if="!$last">
<a href="#">
<span class="glyphicon glyphicon-minus orange" ng-click="deleteRow($index)"></span>
</a>
</td>
</tr>
</table>
JS
$scope.rvm = [{}];
$scope.GetAccountBalance = function (index, c) {
var getPendingData = ReceiptsService.GetPendings(c);
getPendingData.then(function (d) {
$scope.ReceiptsViewModel = d.data;
}, function (error) {
alert('Error');
});
//for (x in d.data) {
// if (d.data.Party == c) {
// var newdata = d.data;
// $scope.ReceiptsViewModel[x] = newdata;
// }
// }
//adding row on plus click
$scope.addRow = function (index, c) {
if ($scope.rvm.length == (index + 1)) {
$scope.rvm.push({
});
}
}
$scope.deleteRow = function ($index) {
$scope.rvm.splice($index, 1);
}
}
public JsonResult GetPendings(int? pendingID)
{
string eid = pendingID.ToString();
TestDemoEntities db = new TestDemoEntities();
var data = (from ap in db.Accounting_PendingBills
join apa in db.Accounting_PendingBillsAdjusted on ap.BillRef equals apa.TowardsBillRef
group apa by new { ap.BillDate, ap.Amount, ap.Party, apa.TowardsBillRef } into g
select new
{
Amount = g.Key.Amount,
Pendings= g.Sum(aa => aa. Pendings)
}).Where(ap => ap.Party == eid).FirstOrDefault();
// }).Where(ap => ap.Party == eid).ToList();
return Json(data, JsonRequestBehavior.AllowGet);
}

Answers (1)