Aug 31, 2013, 6:36 PM
[CLOSED] EditableGrid Saving issue while populate default values in the grid
Hi,
I need to implement the saving functionality of EditableGrid where some fields will populate while loading the grid and some fields will enter or modify populated page ranges. I need to save all data information in the grid. Below I just created one example, which one can save data if any changes happened to grid fields, it is saving only modified fields data. I would like to save the complete grid data. Please run the code and add some numbers in the from and to fields, then click save, the message will show the data. Now reload the page and click on "Populate Ranges". This will populate some default values in the fields. Now change any fields and click save will show only changed info, but I need to get both existing and modified data.
I need to implement the saving functionality of EditableGrid where some fields will populate while loading the grid and some fields will enter or modify populated page ranges. I need to save all data information in the grid. Below I just created one example, which one can save data if any changes happened to grid fields, it is saving only modified fields data. I would like to save the complete grid data. Please run the code and add some numbers in the from and to fields, then click save, the message will show the data. Now reload the page and click on "Populate Ranges". This will populate some default values in the fields. Now change any fields and click save will show only changed info, but I need to get both existing and modified data.
<%@ Page Language="VB" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim populateData As Boolean
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Ext.Net.X.IsAjaxRequest Then
populateData = False
Call LoadGridInfo()
End If
End Sub
Public Sub LoadGridInfo()
storeTests.DataSource = GetDataInfo()
storeTests.DataBind()
End Sub
Public Function GetDataInfo() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
Dim i As Integer
dt.Columns.Add("TEST_ID")
dt.Columns.Add("TESTNAME")
dt.Columns.Add("PAGE_FROM")
dt.Columns.Add("PAGE_TO")
For i = 1 To 10
dr = dt.NewRow()
dr(0) = i
dr(1) = "Test " & i.ToString()
If populateData Then
dr(2) = i
dr(3) = i + 1
Else
dr(2) = ""
dr(3) = ""
End If
dt.Rows.Add(dr)
Next
Return dt
End Function
Public Sub StoreCond_BeforeStoreChanged(ByVal sender As Object, ByVal e As BeforeStoreChangedEventArgs)
Dim jsonData As String = e.DataHandler.JsonData
Ext.Net.X.Msg.Alert("Saved", jsonData).Show()
End Sub
Public Sub MyUAData_Refresh(ByVal sender As Object, ByVal e As StoreRefreshDataEventArgs)
Call LoadGridInfo()
End Sub
Public Sub PopulatePageRanges(ByVal sender As Object, ByVal e As DirectEventArgs)
populateData = True
Call LoadGridInfo()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.Net.Example</title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="resMngr" runat="server" />
<ext:Viewport ID="Viewport1" runat="server" Layout="Border">
<Items>
<ext:Panel ID="pnlCondGrid" runat="server" Region="Center" BodyStyle="background-color:#ededed;"
Margins="5,5,5,5" Layout="BorderLayout" Border="true" ButtonAlign="Center">
<TopBar>
<ext:Toolbar ID="Toolbar4" runat="server" Height="28">
<Items>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:GridPanel ID="grdAllTests" runat="server" Region="Center" BodyStyle="background-color:#DFE8F6"
Border="false" AutoExpandColumn="TESTNAME" StripeRows="true">
<Plugins>
<ext:EditableGrid ID="edgrdTests" runat="server" />
</Plugins>
<Store>
<ext:Store ID="storeTests" runat="server" RefreshAfterSaving="Always" OnBeforeStoreChanged="StoreCond_BeforeStoreChanged" OnRefreshData="MyUAData_Refresh">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="TEST_ID" />
<ext:RecordField Name="TESTNAME" />
<ext:RecordField Name="PAGE_FROM" />
<ext:RecordField Name="PAGE_TO" />
</Fields>
</ext:JsonReader>
</Reader>
<AutoLoadParams>
<ext:Parameter Name="start" Value="0" Mode="Raw" />
<ext:Parameter Name="limit" Value="20" Mode="Raw" />
</AutoLoadParams>
</ext:Store>
</Store>
<SaveMask ShowMask="true" />
<ColumnModel ID="ColumnModel3" runat="server">
<Columns>
<ext:Column Header="Test" DataIndex="TESTNAME">
</ext:Column>
<ext:Column Header="Page From" DataIndex="PAGE_FROM" Width="100">
<Editor>
<ext:TextField ID="txtPageFrom" runat="server" EnableKeyEvents="true">
</ext:TextField>
</Editor>
</ext:Column>
<ext:Column Header="Page To" DataIndex="PAGE_TO" Width="100">
<Editor>
<ext:TextField ID="txtPageTo" runat="server" EnableKeyEvents="true">
</ext:TextField>
</Editor>
</ext:Column>
<ext:CommandColumn Width="100">
<Commands>
<ext:GridCommand Text="Reject" ToolTip-Text="Reject row changes" CommandName="condreject"
Icon="ArrowUndo" />
</Commands>
<PrepareToolbar Handler="toolbar.items.get(0).setVisible(record.dirty);" />
</ext:CommandColumn>
</Columns>
</ColumnModel>
<Listeners>
<Command Handler="record.reject();" />
</Listeners>
</ext:GridPanel>
</Items>
<Buttons>
<ext:Button ID="btnSave" Text="Save" runat="server">
<Listeners>
<Click Handler="grdAllTests.save()" />
</Listeners>
</ext:Button>
<ext:Button ID="btnPopulate" Text = "Populate Ranges" runat="server">
<DirectEvents>
<Click OnEvent="PopulatePageRanges" />
</DirectEvents>
</ext:Button>
</Buttons>
</ext:Panel>
</Items>
</ext:Viewport>
</form>
</body>
</html>
Last edited by Daniil; Sep 03, 2013 at 3:44 AM.
Reason: [CLOSED]