With my ASP.NET MVC, modal popup, DataTable and SSMS Server application, I have a problem when updating the dataTable.
Am using global variable in my MVC application.
| StockIn Date | Prodcut Name | Batch Number | Quantity | Purchase Price | Sales Price | Edit |
|---|
(function () {
app.controller('ProductStock', ['$scope', '$http', '$compile', function ($scope, $http, $compile) {
$('#summary-dataTable').DataTable({
"footerCallback": function (row, data, start, end, display) {
console.log(data);
var totalAmount = 0;
for (var i = 0; i < data.lenght; i++) {
totalAmount += parseFloat(data[i][4]);
}
//console.log(totalAmount);
},
"processing": false,
"serverSide": false,
"paging": true,
"destroy": true,
pageLength: 25,
createdRow: function (row, data, dataIndex) {
$compile(angular.element(row).contents())($scope);
},
ProductStockList: '<"buttons"B>Bfrtip',
//"dom": "Bfrtip",
"columns": [
{ "data": "StockInDate" },
{ "data": "ProductName" },
{ "data": "BatchName" },
{ "data": "Quantity" },
{ "data": "PurchasePrice" },
{ "data": "SalesPrice" },
{
"data": null, "width": "50px", "render": function (data, type, full, meta) {
return "Edit";
}
},
],
"ajax": {
"url": "/Home/GetAllProductStocks",
"type": "GET",
"dataSrc": "[]",
},
});
// declaring a global scope variable
$scope.ProductStock = new Object();
var init = function () {
GetProducts();
GetBatchs();
GetAllProductStock();
}; // end of init
init(); //init is called
// Global scope variable for productStock
function GetProducts() {
$http.get('/Home/GetAllProduct')
.then(function (response) {
var data = response.data;
$scope.ProductList = data;
});
}
function GetBatchs() {
$http.get('/Home/GetAllBatch')
.then(function (response) {
var data = response.data;
$scope.BatchList = data;
});
}
$scope.getProductStock = function ($ProductQtyId, BatchName) {
return $.ajax({
contentType: 'application/json; charset=ut-8',
dataType: 'json',
type: 'GET',
url: "/Home/UpdateProductStock" + "?ProductQtyId=" + $ProductQtyId + "&BatchName=" + BatchName,
//data: data,
success: function (result) {
console.log(result);
debugger;
$scope.ProductStock = result;
$scope.$apply();
$("#ProductStockModal").modal('show');
},
error: function () {
alert("Error!")
}
});
}
HOME CONTROLLER
public ActionResult UpdateProductStock(int? ProductQtyId, string BatchName)
{
ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();
var dataList = db.tblProductStocks.Include("tblProduct").Include("tblBatch").ToList();
var modifiedData = dataList.Where(a => a.ProductQtyId == ProductQtyId).Select(x => new
//var modifiedData = dataList.Select(x => new
{
ProductQtyId = x.ProductQtyId,
ProductId = x.ProductId,
StockInDate = x.StockInDate,
ProductName = x.tblProduct.ProductName,
Quantity = x.Quantity,
BatchId = x.BatchId,
BatchName = x.tblBatch.BatchName,
PurchasePrice = x.PurchasePrice,
SalesPrice = x.SalesPrice
}).FirstOrDefault();
return Json(modifiedData, JsonRequestBehavior.AllowGet);
}
Replies
Know the answer? Post it — somebody with the same question will find it here.