PDA

View Full Version : [CLOSED] SelectionModel returning last selected record in code behind.



ljankowski
Jun 26, 2013, 9:08 PM
Ok simple one guys. I have a gridpanel and selection model and I'm clicking the row and deleting it from the database and then refreshing the datasource of the store. It works the first time after that it shows me the recordID of the last deleted row. Any ideas?

Markup


<ext:Viewport runat="server" ID="uxViewPort" Layout="BorderLayout" IDMode="Explicit" IsDynamic="False" Namespace="App" RenderXType="True">
<Items>
<ext:GridPanel ID="uxSecurityRoleGridPanel"
runat="server"
Title="System Roles"
Padding="5"
Icon="User"
Region="Center"
Frame="true"
Margins="5 5 5 5" >
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="Add Role" Icon="UserAdd">
<DirectEvents>
<Click OnEvent="deAddRole"></Click>
</DirectEvents>
</ext:Button>
<ext:ToolbarSeparator runat="server">
</ext:ToolbarSeparator>
<ext:Button runat="server" Text="Edit Role" Icon="UserEdit"></ext:Button>
<ext:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
</ext:ToolbarSeparator>
<ext:Button runat="server" Text="Delete Role" Icon="UserDelete">
<DirectEvents>
<Click OnEvent="deDeleteRole"><Confirmation ConfirmRequest="true" Message="Are you sure you want to delete this role?"></Confirmation>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store
ID="uxSecurityRoleStore"
runat="server" OnReadData="deSecurityRoleRefresh">
<Model>
<ext:Model ID="uxSecurityRoleModel" runat="server" IDProperty="ROLE_ID">
<Fields>
<ext:ModelField Name="ROLE_ID" Type="Int" />
<ext:ModelField Name="NAME" Type="String" />
<ext:ModelField Name="DESCRIPTION" Type="String"/>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="uxSecurityRoleColumns" runat="server">
<Columns>
<ext:Column ID="cName" runat="server" DataIndex="NAME" Text="Name" Flex="1" />
<ext:Column ID="cDescription" runat="server" DataIndex="DESCRIPTION" Text="Description" Flex="1" />
</Columns>
</ColumnModel>
<Features>
<ext:GridFilters runat="server" ID="uxSecurityRoleGridFilters" Local="true">
<Filters>
<ext:StringFilter DataIndex="NAME" />
<ext:StringFilter DataIndex="DESCRIPTION" />
</Filters>
</ext:GridFilters>
</Features>
<BottomBar>
<ext:PagingToolbar ID="uxSecurityRolePaging" runat="server" />
</BottomBar>
<SelectionModel>
<ext:RowSelectionModel ID="uxSecurityRoleSelectionModel" runat="server" Mode="Single" >
</ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>

</Items>
</ext:Viewport>


code for delete


public void deDeleteRole(object sender, DirectEventArgs e)
{
RowSelectionModel sm = uxSecurityRoleGridPanel.GetSelectionModel() as RowSelectionModel;
long ROLE_ID = long.Parse(sm.SelectedRow.RecordID);
DBI.Data.DataFactory.Security.Roles.DeleteRoleByID (ROLE_ID);

//Refresh the Security Roles View
uxSecurityRoleStore.DataSource = DBI.Data.DataFactory.Security.Roles.RoleList();
uxSecurityRoleStore.DataBind();

}

ljankowski
Jun 26, 2013, 9:17 PM
Sorry this works 2 times, fails after the 3rd attempt...

ljankowski
Jun 26, 2013, 10:11 PM
I believe I fixed it by clearing the selection model on delete but shouldn't that happen auto "magically" on a databind?

Baidaly
Jun 27, 2013, 3:05 AM
Hello!


I believe I fixed it by clearing the selection model on delete but shouldn't that happen auto "magically" on a databind?

We are investigating.

In my opinion, it is better to send them from the client side: http://examples2.ext.net/#/GridPanel/Selection_Models/Row_Selection/

Daniil
Jun 27, 2013, 7:49 AM
Hi everybody,

It is because of a GridPanel's SelectionMemory functionality which is enabled by default. It saves even removed records to have a possibility to restore and submit them in, for example, a case with remote paging. In your case you could switch this functionality off by setting up SelectionMemory="false" for the GridPanel.

I will discuss with the colleagues a possibility to turn off SelectionMemory by default if no paging.

ljankowski
Jun 27, 2013, 2:56 PM
Thanks, I'm just going to turn it off for now. We don't use any remote paging at this point and it easy enough to turn off and on based on our needs.

Daniil
Jun 28, 2013, 3:40 PM
Finally, we considered it a bug. Now, if no paging the removed records after data binding should be eliminated from selection memory. Thank you for the question!