Skip to content

Instantly share code, notes, and snippets.

@A2H111
Created April 8, 2017 04:36
Show Gist options
  • Save A2H111/b84a16607cfe32454f52c7e66c131972 to your computer and use it in GitHub Desktop.
Save A2H111/b84a16607cfe32454f52c7e66c131972 to your computer and use it in GitHub Desktop.
//Class to hold the customer data
$scope.Customer = {
customerID: '',
companyName: '',
contactName: '',
contactTitle: ''
};
//Function to save the data
//Here we pass the row object as parmater, we use this row object to identify the edited row
$scope.saveRow = function (row) {
//get the index of selected row
var index = $scope.gridOptions.data.indexOf(row);
//Remove the edit mode when user click on Save button
$scope.gridOptions.data[index].editrow = false;
//Assign the updated value to Customer object
$scope.Customer.customerID = row.CustomerID;
$scope.Customer.companyName = row.CompanyName;
$scope.Customer.contactName = row.ContactName;
$scope.Customer.contactTitle = row.ContactTitle;
//Call the function to save the data to database
CustomerService.SaveCustomer($scope).then(function (d) {
//Display Successfull message after save
$scope.alerts.push({
msg: 'Data saved successfully',
type: 'success'
});
}, function (d) {
//Display Error message if any error occurs
$scope.alerts.push({
msg: d.data,
type: 'danger'
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment