Apr 18, 2017, 1:16 PM
[CLOSED] Grid Panel editing
I am trying to prevent editing based on a value in code behind. In the example the statement "if 1=2" would be some business logic/condition. I am returning false thinking that should prevent editing but it does not.
<%@ Page Language="vb" %>
<script runat="server">
Private Class GridDTO
Property ID As Integer
Property Trade As Boolean = True
Property Type As String
Property ChangeGuidance As String
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack AndAlso Not Ext.Net.X.IsAjaxRequest Then
Dim data As New List(Of GridDTO)
Dim X = New GridDTO With {.ID = 1, .Trade = True, .ChangeGuidance = ""}
data.Add(X)
X = New GridDTO With {.ID = 2, .Trade = True, .ChangeGuidance = "Test Guidance"}
data.Add(X)
X = New GridDTO With {.ID = 3, .Trade = False, .ChangeGuidance = ""}
data.Add(X)
storeVerification.DataSource = data
storeVerification.DataBind()
End If
End Sub
<DirectMethod([Namespace]:="ModelHoldingsGrid")>
Public Function BeforeEdit() As Boolean
If 1 = 2 Then
Return True
Else
Return False
End If
End Function
<DirectMethod([Namespace]:="VerificationGrid")>
Public Sub Edit(id As Integer)
Me.grdAllocationsVerification.GetStore().GetById(id).Commit()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Edit Grid</title>
<script type="text/javascript">
var verificationEdit = function (editor, e) {
if (!(e.value === e.originalValue)) {
VerificationGrid.Edit(e.record.data.ID);
}
}
var beforeEdit = function (data) {
this.oldValues = Ext.net.clone(data);
return ModelHoldingsGrid.BeforeEdit();
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<ext2:ResourceManager ID="ResourceManager1" runat="server" />
<ext2:Panel Title="Model Change Verification" runat="server" ID="pnlVerification">
<Items>
<ext2:GridPanel Title="Allocation Changes" runat="server" ID="grdAllocationsVerification" AutoScroll="true">
<Store>
<ext2:Store ID="storeVerification" runat="server" >
<Model>
<ext2:Model runat="server" IDProperty="ID">
<Fields>
<ext2:ModelField Name="ID"></ext2:ModelField>
<ext2:ModelField Name="Trade"></ext2:ModelField>
<ext2:ModelField Name="Type"></ext2:ModelField>
<ext2:ModelField Name="ChangeGuidance"></ext2:ModelField>
</Fields>
</ext2:Model>
</Model>
</ext2:Store>
</Store>
<ColumnModel>
<Columns>
<ext2:Column ID="Column1" runat="server" DataIndex="ID" Hidden="true"></ext2:Column>
<ext2:CheckColumn MaxWidth="50" runat="server" DataIndex="Trade" Text="Trade?" Editable="true" ></ext2:CheckColumn>
<ext2:Column runat="server" MaxWidth="40" DataIndex="Type" Text="Type"></ext2:Column>
<ext2:Column runat="server" DataIndex="ChangeGuidance" Text="Change Guidance" Editable="true">
<Editor>
<ext2:TextArea runat="server" ID="txtChangeGuidance" MaxLengthText="100"></ext2:TextArea>
</Editor>
</ext2:Column>
</Columns>
</ColumnModel>
<Plugins>
<ext2:RowEditing runat="server">
<Listeners>
<BeforeEdit Handler="return beforeEdit(e.record.data);"></BeforeEdit>
<Edit Fn="verificationEdit" />
</Listeners>
</ext2:RowEditing>
</Plugins>
</ext2:GridPanel>
</Items>
</ext2:Panel>
</form>
</body>
</html>
Last edited by fabricio.murta; Apr 19, 2017 at 3:09 PM.