I have one table on database
AutoPopList
id value
1 10
2 12
3 13
4 9
I am populating taxes (id,value)values from database
I need row total value based upon basic amount and value
row total=basicamount *value/100
and also i need tax total the elements those which are selected
and i want to push chekced elements in above row after clicking of add button
public JsonResult getAll1()
{
List<AutoPopList> Emp = db.AutoPopLists.ToList();
return Json(Emp, JsonRequestBehavior.AllowGet);
}
<html>
<head>
<title>Index</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script src="~/scripts/dirpagination.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', ['angularUtils.directives.dirPagination'])
app.controller('MyController', function ($scope, $http, $window, RegistrationService) {
$scope.change = function (i) {
debugger;
var total = 0;
for (var i = 0; i < $scope.taxes.length; i++) {
if ($scope.taxes[i].Selected) {
total += $scope.taxes[i].rowtotal;
}
}
$scope.taxtotal = parseFloat(total).toFixed(2);
};
$scope.basicChange = function (i) {
$scope.taxes[i].rowtotal = $(this)[0].basicamount * $scope.taxes[i].value / 100;
};
function loadEmployees() {
var EmployeeRecords = RegistrationService.gettaxes();
EmployeeRecords.then(function (d) {
$scope.taxes = d.data;
}, function () {
alert("Error occured while fetching employee list...");
});
}
$scope.Customers = [];
$scope.taxes = [];
$scope.newtaxes = [];
$scope.change1 = function (i) {
debugger;
if ($(this)[0].checkbox) {
$scope.newtaxes.push($scope.taxes[i]);
}
else {
$scope.newtaxes.pop($scope.taxes[i]);
}
};
$scope.Add = function () {
loadEmployees();
//Add the new item to the Array.
var customer = {};
customer.basicamount = $scope.basicamount;
customer.taxes = $scope.newtaxes;
customer.taxtotal = $scope.taxtotal;
$scope.Customers.push(customer);
//Clear the TextBoxes.
$scope.newtaxes = [];
$scope.basicamount = "";
$scope.taxtotal = "";
};
});
app.service("RegistrationService", function ($http) {
this.gettaxes = function () {
return $http.get("/dynamicaalyAddRemove/getAll1");
};
});
</script>
</head>
</html>