This is a migrated thread and some comments may be shown as answers.

Batch Edit Validation in Hierarchical Grid

2 Answers 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brxton
Top achievements
Rank 1
Brxton asked on 29 Sep 2015, 02:42 PM

Hello,

 I have a radgrid in Batch Edit mode that I want to perform some validation on before postback. This worked for me just fine when the grid was one level (no children), but if I want to add a second level to the hierarchy (one child) then the validation causes code errors.

 This seems to come from SaveAllHierarchyLevels="true". When this is true, it causes the args.set_cancel(true) in the validation step to create issues if the same line is edited and fixed after failing validation, then saved. I believe it has something to do with the differences between the BatchEdit command and the GlobalBatchEdit command.

 Is there something I need to do to implement client-side GlobalBatchEdit validation specifically, that is not part of BatchEdit validation?

function ValidateCommand(sender, args) {
            var failed = false;
            var indic = "";
            //alert(totals[0] + " " + totals[1] + " " + totals[2] + " " + totals[3] + " " + totals[4] + " " + totals[5] + " " + totals[6]);
            checksum();
            for (var i = 0; i < 7; i++) {
                if (totals[i] > 24.0) {
                    failed = true;
                    indic += "Too much time entered! Cannot have more than 24 hours per day. \n";
                    break;
                }
            }
  
            var radGrid = $find('<%= WeeklyTimeGrid.ClientID %>');
            var batchManager = radGrid.get_batchEditingManager();
            var masterTable = radGrid.get_masterTableView();
            var rows = masterTable.get_dataItems();
            var size = rows.length;
  
            for (i = 0; i < size; i++) {
                var s = masterTable.getCellByColumnUniqueName(rows[i], "Phase");
                //alert("(" + s.innerText.trim() + ")");
                if (s.innerText.trim() == "") {
                    indic += "Phase code is required!\n";
                    failed = true;
                    break;
                }
            }
  
            //alert(failed + " " + args.get_commandName() + " " + args.get_commandArgument());
            if (failed && args.get_commandName() == "BatchEdit") { //<--Becomes 'GlobalBatchEdit'
                args.set_cancel(true);
                alert(indic);
            }
        }

protected void WeeklyTimeGrid_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
        {
            string a = _BatchID; //refresh batch info from db
 
            SavedChangesList.Visible = true;
 
            //If the batch is locked...
            if (readyToExport != 0 || hasBeenExported != 0)
            {
                //...don't do anything
                e.Canceled = true;
                NotifyUser("The batch was locked by another user, or has been exported");
                if (WeeklyTimeGrid.Enabled)
                {
                    ToggleBatchLock();
                }
 
                return;
            }
 
            foreach (GridBatchEditingCommand c in e.Commands)
            {//Here is where GlobalBatchEdit fails and BatchEdit is fine (after failing validation once, then correcting and saving)
                if (c.Item == null)
                {
                    c.Canceled = true;
                    NotifyUser("There was an error updating time, please try again. If the problem persists, please contact IT.");
                }
            }
 
            UpdateSelectedEmpTime(e.Commands);
        }

2 Answers, 1 is accepted

Sort by
0
Brxton
Top achievements
Rank 1
answered on 30 Sep 2015, 06:37 PM
I figured out my issue. I was using OnBatchEditOpening and OnBatchEditClosed to prevent people navigating away with unsaved changes, but this caused the saving to behave unexpectedly. Now I set a flag in the OnBatchEditCellValueChanging event and everything is working, but I had no idea that those two events would change the way the GlobalBatchEdit command behaved.
0
Maria Ilieva
Telerik team
answered on 02 Oct 2015, 11:16 AM
Hello ,

Based on the provided description I was not able to completely understand the exact issue you were initially facing. Are you trying to cancel the events and in this case the validation stops working? Please elaborate a bit more on the exact case you have so that we can advise you for the best solution and give more information on why the applied approach works in your case.

Regards,
Maria Ilieva
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Brxton
Top achievements
Rank 1
Answers by
Brxton
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or