jQuery UI Widgets › Forums › Grid › addrow and update row in the same function
Tagged: addrow, Angular, angular grid, angularjs, grid, jquery grid, jqxgrid, scope, updaterow
This topic contains 4 replies, has 2 voices, and was last updated by Dimitar 8 years, 4 months ago.
-
Author
-
Hi,
I have four buttons “ADD, Edit, Save, Cancel” in my webpage.
To Add data to the grid, Click on Add button and then Save button.
To Edit the data in the grid, Click on Edit make changes and click save button to save it back to the grid.The data is added and edited on clicking the save button.
How can I use “addrow” and “updaterow methods in the same “save function, below is my piece of code.` $scope.save = function()
{
var data = {
ClientId: $scope.clientIdSettings.jqxInput(‘val’),
ClientName: $scope.clientNameSettings.jqxInput(‘val’)
};
$scope.gridSettings.jqxGrid(‘addrow’, null, data);
var rows = $scope.gridSettings.jqxGrid(‘getrows’);
$scope.gridSettings.jqxGrid(‘selectrow’,rows.length-1 );
$scope.clientIdSettings.jqxInput(‘val’, ”);
$scope.clientNameSettings.jqxInput(‘val’, ”);var rowID = $scope.gridSettings.jqxGrid(‘getrowid’, editrow);
$scope.gridSettings.jqxGrid(‘updaterow’, rowID, data);
$scope.clientIdSettings.jqxInput(‘val’, ”);
$scope.clientNameSettings.jqxInput(‘val’, ”);};
});
Also how can I cancel if I don’t want to edit or add? That is when I click on a row to edit and then without saving wanted to cancel it.
Thanks,
Hi KBhima,
I think you can achieve this by using a flag variable (called, for example, mode). If “Add” is clicked, set mode to ‘add’. If “Edit” is clicked, set it to ‘edit’. In $scope.save, check for the value of mode and call either addrow or updaterow depending on its value.
To cancel the add or edit action, you can have another button, “Cancel”, which clears the add/edit inputs.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Am doing this for cancel, but it doesn’t work.
$scope.cancel = function (row,event) {
event.cancel =true;
}It does not clear off anything.
Hi KBhima,
By “clearing the add/edit inputs” I meant setting their values (with val) to empty strings (“”).
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.