问题
I have the following code within my .aspx file
<ext:GridPanel
runat="server"
ID="GridPanel1"
Height="450"
Title="EmployeeList"
Width = "850"
Header = "false"
StyleSpec = "margin: 25px;"
StripeRows="true"
TrackMouseOver="true"
Border="true" ClicksToEdit="2">
<Store>
<ext:Store ID="Store1" runat="server" DataSourceID="LinqDataSource1">
<Reader>
<ext:JsonReader IDProperty="id" >
<Fields>
<ext:RecordField Name="id" />
<ext:RecordField Name="shortcode" />
<ext:RecordField Name="lastname" />
<ext:RecordField Name="firstname" />
<ext:RecordField Name="roomnumber" />
<ext:RecordField Name="landline" />
<ext:RecordField Name="mobile" />
<ext:RecordField Name="mail" />
<ext:RecordField Name="position" />
<ext:RecordField Name="department" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server" >
<Columns>
<ext:Column DataIndex="id" Header="Index" Width="50"/>
<ext:Column DataIndex="shortcode" Header="Kuerzel" Align="Center" />
<ext:Column DataIndex="lastname" Header="Nachname" />
<ext:Column DataIndex="firstname" Header="Vorname" />
<ext:Column DataIndex="roomnumber" Header="Raumnummer" Align="Center" Width="50"/>
<ext:Column DataIndex="landline" Header="Durchwahl intern" Align="Center" Width="50"/>
<ext:Column DataIndex="mobile" Header="Durchwahl handy" Align="Center" Width="50"/>
<ext:Column DataIndex="mail" Header="Mail" />
<ext:Column DataIndex="position" Header="Funktion" />
<ext:Column DataIndex="department" Header="Abteilung" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" SingleSelect="true">
<%-- <Listeners>
<RowSelect Handler="#{EditPanel}.getForm().loadRecord(record);" />
</Listeners>--%>
<DirectEvents>
<RowSelect OnEvent="SaveCurrentSelection">
<ExtraParams>
<ext:Parameter Name="usID" Value="this.getSelected().id" Mode="Raw" />
</ExtraParams>
</RowSelect>
</DirectEvents>
</ext:RowSelectionModel>
</SelectionModel>
<KeyMap>
<ext:KeyBinding Ctrl="true">
<Keys>
<ext:Key Code="Y" />
</Keys>
<Listeners>
<Event Handler="#{DirectMethods}.ShowSearchWindow();" />
</Listeners>
</ext:KeyBinding>
</KeyMap>
<DirectEvents>
<RowDblClick OnEvent="SwitchToUserDetail">
<ExtraParams>
<ext:Parameter Name="id" Value="this.selModel.getSelected().id" Mode="Raw"></ext:Parameter>
</ExtraParams>
</RowDblClick>
</DirectEvents>
</ext:GridPanel>
Now I need to get the id field of the currently selected row as how I get it within my RowSelect Listener
<ext:Parameter Name="usID" Value="this.getSelected().id" Mode="Raw" />
But this time not within the SelectionModel. I need to get it here:
<DirectEvents>
<RowDblClick OnEvent="SwitchToUserDetail">
<ExtraParams>
<ext:Parameter Name="id" Value="this.selModel.getSelected().id" Mode="Raw"></ext:Parameter>
</ExtraParams>
</RowDblClick>
</DirectEvents>
Outside of the SelectionModel but inside the GridPanel.
I think the way is to get it here:
Value = "this.selModel.getSelected().id"
I need to get that here as I don't want to do it inside the CodeBehind and as the Listener and DirectEvent does not work together in my SelectionModel
An answer will be appreciated
回答1:
You can access field of record like this
this.selModel.getSelected().data.shortcode
回答2:
Unfortunately that didn't work for me:
App.GridPanel1.getSelectionModel().getSelected().data.Id
But this:
App.GridPanel1.getSelectionModel().getSelected().items[0].data.Id
回答3:
This has changed in later versions of Ext.NET. To get the IDProperty of the row, notice that "getSelected()" is now "getSelection()" and the function returns an array of selected objects:
<SelectionModel>
<ext:RowSelectionModel runat="server">
<Listeners>
<Select Handler="#{GridPanel1}.selModel.getSelection()[0].internalId" />
</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
来源:https://stackoverflow.com/questions/7913036/how-to-get-values-from-the-currently-selected-row-within-a-ext-net-gridpanel-out