Whenever i add new record of RadGrid Batch Edit mode, I'll have a new row with <tr> ID like: RadGrid1_ctl00__-1,RadGrid1_ctl00__-2,RadGrid1_ctl00__-3....
So how do I get that ID of my current selected row ( contain my pointer ) by script code.
I have tried to use get_itemIndex() but its not working.
Tks
Hiep
3 Answers, 1 is accepted
0
Hello Hiep,
For your convenience, following is an example demonstrating how to get the ID of the TR element corresponding to a an item:
As you can notice, we are using get_id() method to get the generated ID for the TR element.
Hope this helps.
Regards,
Konstantin Dikov
Telerik
For your convenience, following is an example demonstrating how to get the ID of the TR element corresponding to a an item:
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function getSelectedRowID() {
var grid = $find("<%=RadGrid1.ClientID%>");
if (grid.get_selectedItems().length > 0) {
var selectedItem = grid.get_selectedItems()[0];
var id = selectedItem.get_id();
}
}
</
script
>
</
telerik:RadCodeBlock
>
<
asp:Button
Text
=
"Get selected row ID"
OnClientClick
=
"getSelectedRowID(); return false;"
runat
=
"server"
/>
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
ClientSettings-Selecting-AllowRowSelect
=
"true"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
EditMode
=
"Batch"
>
</
MasterTableView
>
</
telerik:RadGrid
>
As you can notice, we are using get_id() method to get the generated ID for the TR element.
Hope this helps.
Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items
0
Hiep
Top achievements
Rank 1
answered on 17 Jun 2015, 09:00 AM
Hi Konstantin
Your demo worked fine with mouse pointer but when my job is use tab key to go to next row. So when i use tab to go down, it still return the row what i choose by mouse. Can you help me solve this problem ?
Many thanks
Hiep
0
Hi Hiep,
When you enable the keyboard navigation in the grid and when you use the Tab key to navigate through cells and rows, when you move to another row, that row will not be the selected one, so it is expected that the selectedItem.get_id method will return the id of the selected row. If you need to change the selection depending on the last edited row you could try the following approach:
This will force the currently edited row to be the selected one.
Regards,
Konstantin Dikov
Telerik
When you enable the keyboard navigation in the grid and when you use the Tab key to navigate through cells and rows, when you move to another row, that row will not be the selected one, so it is expected that the selectedItem.get_id method will return the id of the selected row. If you need to change the selection depending on the last edited row you could try the following approach:
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function pageLoad() {
$find("<%=RadGrid1.ClientID%>").get_masterTableView().get_dataItems();
}
function getSelectedRowID() {
var grid = $find("<%=RadGrid1.ClientID%>");
if (grid.get_selectedItems().length > 0) {
var selectedItem = grid.get_selectedItems()[0];
var id = selectedItem.get_id();
console.log(id);
}
}
function editOpened(sender, args) {
if (sender.get_selectedItems().length > 0) {
sender.get_selectedItems()[0].set_selected(false);
}
$find(args.get_row().id).set_selected(true);
}
</
script
>
</
telerik:RadCodeBlock
>
<
asp:Button
ID
=
"Button1"
Text
=
"Get selected row ID"
OnClientClick
=
"getSelectedRowID(); return false;"
runat
=
"server"
/>
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
ClientSettings-Selecting-AllowRowSelect
=
"true"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
EditMode
=
"Batch"
>
</
MasterTableView
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
>
<
ClientEvents
OnBatchEditOpened
=
"editOpened"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
This will force the currently edited row to be the selected one.
Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items