Greetings,
I wanted to use the saveTableChanges(tableViews) method for my RadGrids in BatchEdit mode. I have 3 different grids and I want to save their changes in one postback with my own Save button that is external to the grid. The saveBatchChanges function below is fired on save:
function
saveBatchChanges() {
var
grid1 = $find(
"<%=RadGridApprovalsequence1.ClientID %>"
);
var
grid2 = $find(
"<%=RadGridApprovalsequence2.ClientID %>"
);
var
grid3 = $find(
"<%=RadGridApprovalsequence3.ClientID %>"
);
var
tableView1 = grid1.get_masterTableView();
var
tableView2 = grid2.get_masterTableView();
var
tableView3 = grid3.get_masterTableView();
var
tableViews = [];
tableViews.push(tableView1);
tableViews.push(tableView2);
tableViews.push(tableView3);
var
batchManager1 = grid1.get_batchEditingManager();
var
batchManager2 = grid2.get_batchEditingManager();
var
batchManager3 = grid3.get_batchEditingManager();
var
grid1Updated = batchManager1._extractChangesString(tableView1) ===
""
?
false
:
true
;
var
grid2Updated = batchManager2._extractChangesString(tableView2) ===
""
?
false
:
true
;
var
grid3Updated = batchManager3._extractChangesString(tableView3) ===
""
?
false
:
true
;
// changes in 1 grid (grid 1)
if
(grid1Updated ==
true
&& grid2Updated ==
false
&& grid3Updated ==
false
) {
batchManager1.saveTableChanges(tableViews);
}
// changes in 1 grid (grid 2)
else
if
(grid2Updated ==
true
&& grid1Updated ==
false
&& grid3Updated ==
false
) {
batchManager2.saveTableChanges(tableViews);
}
// changes in 1 grid (grid 3)
else
if
(grid3Updated ==
true
&& grid1Updated ==
false
&& grid2Updated ==
false
) {
batchManager3.saveTableChanges(tableViews);
}
// changes in 2 grids (grids 1 and 2)
else
if
(grid1Updated ==
true
&& grid2Updated ==
true
&& grid3Updated ==
false
) {
batchManager1.saveTableChanges(tableViews);
// THIS FAILS!
}
// changes in 2 grids (grids 1 and 3)
else
if
(grid1Updated ==
true
&& grid2Updated ==
false
&& grid3Updated ==
true
) {
batchManager1.saveTableChanges(tableViews);
}
// changes in 2 grids (grids 2 and 3)
else
if
(grid1Updated ==
false
&& grid2Updated ==
true
&& grid3Updated ==
true
) {
batchManager2.saveTableChanges(tableViews);
}
// changes in all 3 grids
else
{
batchManager1.saveTableChanges(tableViews);
}
};
For some reason, if only 1 grid is updated, the batchManager1.saveTableChanges(tableViews) method works, but not when more than 1 grid is updated. In IE I noticed a JavaScript error on the call to saveTableChanges ("Unable to get property 'cell' of undefined or null reference"). It does not do the postback for me and my handler on the server side (RadGridApprovalsequence1_BatchEditCommand) is never triggered. Below is the handler:
protected void RadGridApprovalsequence1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
BatchEditCommand(sender, e);
}
protected void RadGridApprovalsequence2_BatchEditCommand(object sender, Telerik.Web.UI.GridBatchEditingEventArgs e)
{
BatchEditCommand(sender, e);
}
protected void RadGridApprovalsequence3_BatchEditCommand(object sender,Telerik.Web.UI.GridBatchEditingEventArgs e)
{
BatchEditCommand(sender, e);
}
protected void BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
// Save logic here
}
Here is the one of the grids (the other 2 are similar):
<
telerik:RadGrid
ID
=
"RadGridApprovalsequence1"
ToolTip
=
"Grid 1 Approval Flow"
GridLines
=
"None"
runat
=
"server"
PageSize
=
"12"
AllowPaging
=
"True"
AutoGenerateColumns
=
"False"
OnItemDataBound
=
"RadGridApprovalsequence1_ItemDataBound"
OnItemCommand
=
"RadGridApprovalsequence1_ItemCommand"
AllowAutomaticUpdates
=
"False"
AllowAutomaticInserts
=
"False"
OnBatchEditCommand
=
"RadGridApprovalsequence1_BatchEditCommand"
Width
=
"450px"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
MasterTableView
Width
=
"100%"
CommandItemDisplay
=
"TopAndBottom"
CommandItemSettings-AddNewRecordText
=
"Add New Step"
DataKeyNames
=
"TaskStageDisplayName,ApprovalStep,SubRole,DaysToApprove"
AutoGenerateColumns
=
"False"
EditMode
=
"Batch"
>
<
BatchEditingSettings
EditType
=
"Cell"
/>
<
CommandItemSettings
ShowSaveChangesButton
=
"false"
ShowCancelChangesButton
=
"false"
/>
<
Columns
>
<
telerik:GridTemplateColumn
HeaderText
=
"Task Stage"
UniqueName
=
"TaskStage"
Visible
=
"false"
>
<
ItemTemplate
>
<%# DataBinder.Eval(Container.DataItem, "TaskStageDisplayName")%>
</
ItemTemplate
>
<
HeaderStyle
Font-Bold
=
"True"
Font-Names
=
"Arial"
Width
=
"150px"
/>
<
ItemStyle
Font-Names
=
"Arial"
/>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Step"
UniqueName
=
"ApprovalStep"
>
<
ItemTemplate
>
<%# DataBinder.Eval(Container.DataItem, "ApprovalStep")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
ToolTip
=
"Approval Step"
Type
=
"Number"
Value
=
"1"
runat
=
"server"
MaxLength
=
"2"
NumberFormat-DecimalDigits
=
"0"
ID
=
"txtApprovalSteps"
Skin
=
"Windows7"
Width
=
"30px"
>
</
telerik:RadNumericTextBox
>
<
span
style
=
"color: Red"
>
<
asp:CompareValidator
ID
=
"CompareValidator1"
runat
=
"server"
ControlToValidate
=
"txtApprovalSteps"
ErrorMessage
=
"*"
Operator
=
"GreaterThanEqual"
Type
=
"Integer"
ValueToCompare
=
"1"
></
asp:CompareValidator
>
</
span
>
</
EditItemTemplate
>
<
HeaderStyle
Font-Bold
=
"True"
Font-Names
=
"Arial"
Width
=
"60px"
/>
<
ItemStyle
Font-Names
=
"Arial"
/>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Approver Role"
UniqueName
=
"SubRole"
>
<
ItemTemplate
>
<%# DataBinder.Eval(Container.DataItem, "SubRole")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"RadComboBoxSubRoles"
Width
=
"190px"
OnClientDropDownOpening
=
"getGrid1SubRoles"
MaxHeight
=
"200px"
>
<
ExpandAnimation
Type
=
"none"
/>
<
CollapseAnimation
Type
=
"none"
/>
</
telerik:RadComboBox
>
<
span
style
=
"color: Red"
>
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator1"
ControlToValidate
=
"RadComboBoxSubRoles"
ErrorMessage
=
"*Required"
runat
=
"server"
Display
=
"Dynamic"
>
</
asp:RequiredFieldValidator
>
</
span
>
</
EditItemTemplate
>
<
HeaderStyle
Font-Bold
=
"True"
Font-Names
=
"Arial"
Width
=
"200px"
/>
<
ItemStyle
Font-Names
=
"Arial"
/>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Days to Approve"
UniqueName
=
"DaysToApprove"
DataField
=
"DaysToApprove"
DataType
=
"System.Int16"
>
<
ItemTemplate
>
<%# DataBinder.Eval(Container.DataItem, "DaysToApprove")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
ToolTip
=
"Days To Approve"
Type
=
"Number"
Value
=
"0"
runat
=
"server"
MaxLength
=
"2"
NumberFormat-DecimalDigits
=
"0"
ID
=
"txtDaysToApprove"
Skin
=
"Windows7"
Width
=
"30px"
>
</
telerik:RadNumericTextBox
>
<
span
style
=
"color: Red"
>
<
asp:CompareValidator
ID
=
"CompareValidator2"
runat
=
"server"
ControlToValidate
=
"txtDaysToApprove"
ErrorMessage=">= 0"
Operator="GreaterThanEqual" Type="Integer"
ValueToCompare="0"></
asp:CompareValidator
>
</
span
>
</
EditItemTemplate
>
<
HeaderStyle
Font-Bold
=
"True"
Font-Names
=
"Arial"
Width
=
"80px"
/>
<
ItemStyle
Font-Names
=
"Arial"
/>
</
telerik:GridTemplateColumn
>
<
telerik:GridButtonColumn
ConfirmText
=
"Delete this Approval Step?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
ImageUrl
=
"~/_layouts/images/DeleteRed20.png"
UniqueName
=
"DeleteColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
/>
<
HeaderStyle
Width
=
"30px"
/>
</
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
> </
FilterMenu
>
</
telerik:RadGrid
>
Question 1: Does it matter which manager I use to save changes happening in more than 1 grid?
Question 2: Is my implementation of the saveTableChanges(tableViews) method correct? If so, why is it not firing my handler while making changes in multiple grids vs. only 1 grid?
Thank you so much!