PDA

View Full Version : API Sync issue with a CheckboxSelectionModel Grid Panel



navalurzu7
Sep 24, 2015, 9:51 PM
Hi.

I have 2 grid panels set up with API Sync to update rows. Problem is, 1 works and 1 does not. please see below:

Here is the working code:

the Javascript function to get the Value of the rows in the grid panel that is called in the SyncParameters of the Store:


<script type="text/javascript">
var getValues = function (grid) {
var records = grid.store.getUpdatedRecords(), values = [];
for (i = 0; i < records.length; i++) {
var dataR = grid.store.prepareRecord(records[i].data, records[i], {});
if (!Ext.isEmptyObj(dataR)) {
values.push(dataR);
}
};
return values
}
</script>



The GridPanel and Store with the API Sync set up that works:


<ext:GridPanel ID="gpMargins"
runat="server"
AutoHeight="true"
EnableViewState="true">
<Store>
<ext:Store ID="dsMarginsO1P"
runat="server"
RemoteSort="true"
PageSize="20">
<Proxy>
<ext:AjaxProxy Url="/Operations/GetMarginsO1P/">
<ActionMethods Read="GET" />
<API Sync="/Operations/UpdateMarginsO1P/" />
<Reader>
<ext:JsonReader Root="data" IDProperty="DealCapID" SuccessProperty="Success" MessageProperty="Message" />
</Reader>
<Writer>
<ext:JsonWriter Root="data" />
</Writer>
</ext:AjaxProxy>
</Proxy>
<Parameters>
<ext:StoreParameter Name="dcid" Value="#{tDcidMargin}.getValue()" Mode="Raw" />
</Parameters>
<SyncParameters>
<ext:StoreParameter Name="data" Value="Ext.encode(getValues(#{gpMargins}))" Mode="Raw" />
</SyncParameters>
<Model>
<ext:Model ID="Model2" runat="server" IDProperty="DealCapID">
<Fields>
<ext:ModelField Name="DealCapID" Type="Int" />
<ext:ModelField Name="GM_MarRate" Type="Float" />
<ext:ModelField Name="Comm_1_Rate" Type="Float" />
<ext:ModelField Name="Comm_2_Rate" Type="Float" />
<ext:ModelField Name="Comm_3_Rate" Type="Float" />
<ext:ModelField Name="SR_Name_1" Type="String" />
<ext:ModelField Name="SR_Name_2" Type="String" />
<ext:ModelField Name="SR_Name_3" Type="String" />
<ext:ModelField Name="SRID" Type="Int" />
<ext:ModelField Name="SRID_2" Type="Int" />
<ext:ModelField Name="SRID_3" Type="Int" />
<ext:ModelField Name="CommCode_1" Type="Int" />
<ext:ModelField Name="CommCode_2" Type="Int" />
<ext:ModelField Name="CommCode_3" Type="Int" />
</Fields>
</ext:Model>
</Model>
<Sorters>
<ext:DataSorter Property="DealCapID" Direction="ASC" />
</Sorters>
<Listeners>
<Write Handler="Ext.Msg.alert('Success', 'The Margins have been saved.');" />
</Listeners>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel3" runat="server">
<Columns>
<ext:Column ID="Column10" runat="server" DataIndex="DealCapID" Text="DCID" Width="70">
</ext:Column>
<ext:Column ID="Column11" runat="server" DataIndex="GM_MarRate" Text="GM_MarRate" Width="100">
<Editor>
<ext:NumberField ID="editGMMarRate" runat="server" MaxLength="10" DecimalPrecision="7"/>
</Editor>
</ext:Column>
<ext:Column ID="Column12" runat="server" DataIndex="Comm_1_Rate" Text="Comm_1_Rate" Width="100">
<Editor>
<ext:NumberField ID="editComm1Rate" runat="server" MaxLength="10" DecimalPrecision="7"/>
</Editor>
</ext:Column>
<ext:Column ID="Column13" runat="server" DataIndex="Comm_2_Rate" Text="Comm_2_Rate" Width="100">
<Editor>
<ext:NumberField ID="editComm2Rate" runat="server" MaxLength="10" DecimalPrecision="7" />
</Editor>
</ext:Column>
<ext:Column ID="Column14" runat="server" DataIndex="Comm_3_Rate" Text="Comm_3_Rate" Width="100">
<Editor>
<ext:NumberField ID="editComm3Rate" runat="server" MaxLength="10" DecimalPrecision="5" />
</Editor>
</ext:Column>
<ext:Column ID="Column15" runat="server" DataIndex="SR_Name_1" Text="SR_Name_1" Width="100">
<Editor>
<ext:TextField ID="editSRName1" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column16" runat="server" DataIndex="SR_Name_2" Text="SR_Name_2" Width="100">
<Editor>
<ext:TextField ID="editSRName2" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column17" runat="server" DataIndex="SR_Name_3" Text="SR_Name_3" Width="100">
<Editor>
<ext:TextField ID="editSRName3" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column18" runat="server" DataIndex="SRID" Text="SRID" Width="40">
<Editor>
<ext:NumberField ID="editSRID1" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column19" runat="server" DataIndex="SRID_2" Text="SRID_2" Width="50">
<Editor>
<ext:NumberField ID="editSRID2" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column20" runat="server" DataIndex="SRID_3" Text="SRID_3" Width="50">
<Editor>
<ext:NumberField ID="editSRID3" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column21" runat="server" DataIndex="CommCode_1" Text="CommCode_1" Width="80">
<Editor>
<ext:NumberField ID="editCommCode1" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column22" runat="server" DataIndex="CommCode_2" Text="CommCode_2" Width="80">
<Editor>
<ext:NumberField ID="editCommCode2" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column23" runat="server" DataIndex="CommCode_3" Text="CommCode_3" Width="80">
<Editor>
<ext:NumberField id="editCommCode3" runat="server" />
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<View>
<ext:GridView ID="GridView1" runat="server" />
</View>
<SelectionModel>
<ext:CellSelectionModel ID="CellSelectionModel1" runat="server" />
</SelectionModel>
<Plugins>
<ext:CellEditing ID="CellEditing1" runat="server">
</ext:CellEditing>
</Plugins>
<BottomBar>
<ext:Toolbar ID="PagingToolbar3"
runat="server">
<Items>
<ext:Button ID="Button3" runat="server" Text="Save" Icon="Disk">
<Listeners>
<Click Handler="#{dsMarginsO1P}.sync(); " />
</Listeners>
</ext:Button>
<ext:ToolbarSeparator ID="ToolbarSeparator3" runat="server" />
<ext:Button ID="Button4" runat="server" Text="Undo Changes" Icon="ArrowRotateAntiClockwise">
<Listeners>
<Click Handler="#{dsMarginsO1P}.reload();" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</BottomBar>
</ext:GridPanel>



The Method in the Controller that is called on API Sync when the Save button is clicked:


Public Function UpdateMarginsO1P(ByVal data As String) As ActionResult
Dim result As New AjaxResult
If Not String.IsNullOrEmpty(data) Then
Dim sorter As Dictionary(Of String, String)() = Ext.Net.JSON.Deserialize(Of Dictionary(Of String, String)())(data)
For Each row As Dictionary(Of String, String) In sorter
Dim id = row("DealCapID")
Dim um As tbl_Offer_1_Price = (From o1p In DBPricingContext.tbl_Offer_1_Prices Where o1p.DealCapID = CInt(id) Select o1p).SingleOrDefault
um.DealCapID = CInt(row("DealCapID"))
um.GM_MarRate = CDec(row("GM_MarRate"))
um.Comm_1_Rate = CDec(row("Comm_1_Rate"))
um.Comm_2_Rate = CDec(row("Comm_2_Rate"))
um.Comm_3_Rate = CDec(row("Comm_3_Rate"))
um.SR_Name_1 = row("SR_Name_1").ToString
um.SR_Name_2 = row("SR_Name_2").ToString
um.SR_Name_3 = row("SR_Name_3").ToString
um.SRID = CInt(row("SRID"))
um.SRID_2 = CInt(row("SRID_2"))
um.SRID_3 = CInt(row("SRID_3"))
um.CommCode_1 = CInt(row("CommCode_1"))
um.CommCode_2 = CInt(row("CommCode_2"))
um.CommCode_3 = CInt(row("CommCode_3"))

Me.DBPricingContext.SubmitChanges()
Next
End If
Return result
End Function




I tried creating a 2nd instance of this working model, but with a Checkbox Selection Model for multiple selects, but no matter what i try, the function in the Controller never gets hit. It looks like the javascript function getValues() doesnt even get hit either, and I've been wracking my brain trying to figure out why. Here is the Grid Panel that does not work:


<ext:GridPanel ID="gpMarginsO3E"
runat="server"
AutoHeight="true"
EnableViewState="true">
<Store>
<ext:Store ID="dsMarginsO3E"
runat="server"
RemoteSort="true"
PageSize="20">
<Proxy>
<ext:AjaxProxy Url="/Operations/GetMarginsO3E/">
<ActionMethods Read="GET" />
<API Sync="/Operations/GetSelectedRows/" />
<Reader>
<ext:JsonReader Root="data" IDProperty="ESIID" SuccessProperty="Success" MessageProperty="Message" />
</Reader>
<Writer>
<ext:JsonWriter Root="data" />
</Writer>
</ext:AjaxProxy>
</Proxy>
<Parameters>
<ext:StoreParameter Name="dcid" Value="#{tDcidMargin}.getValue()" Mode="Raw" />
</Parameters>
<SyncParameters>
<ext:StoreParameter Name="data" Value="Ext.encode(getValues(#{gpMarginsO3E}))" Mode="Raw" />
</SyncParameters>
<Model>
<ext:Model ID="Model3" runat="server" IDProperty="MAIDT">
<Fields>
<ext:ModelField Name="IDofOFFER" Type="Int" />
<ext:ModelField Name="ESIID" Type="Int" />
<ext:ModelField Name="CommCode_1" Type="Int" />
<ext:ModelField Name="CommCode_2" Type="Int" />
<ext:ModelField Name="CommCode_3" Type="Int" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel5" runat="server">
<Columns>
<ext:Column ID="ColIDofOffer" runat="server" DataIndex="IDofOFFER" Text="IDofOffer" Width="80" />
<ext:Column ID="ColESIID" runat="server" DataIndex="ESIID" Text="ESIID" Width="150" />
<ext:Column ID="ColCommCode1" runat="server" DataIndex="CommCode_1" Text="CommCode_1" Width="100" />
<ext:Column ID="ColCommCode2" runat="server" DataIndex="CommCode_2" Text="CommCode_2" Width="100" />
<ext:Column ID="ColCommCode3" runat="server" DataIndex="CommCode_3" Text="CommCode_3" Width="100" />
</Columns>
</ColumnModel>
<View>
<ext:GridView ID="GridView3" runat="server" />
</View>
<SelectionModel>
<ext:CheckboxSelectionModel ID="ckbSelectionModel" runat="server" />
</SelectionModel>
<BottomBar>
<ext:Toolbar ID="PagingToolbar5"
runat="server">
<Items>
<ext:Button ID="btnEditO3E" runat="server" Text="Edit" Icon="ApplicationFormEdit">
<Listeners>
<Click Handler="#{dsMarginsO3E}.sync();" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</BottomBar>
</ext:GridPanel>



And the function it is trying to call in the Controller:


Public Function GetSelectedRows(ByVal data As String) As ActionResult
Return New StoreResult(data)
End Function


Any help or insight is appreciated. Thank you