This is a migrated thread and some comments may be shown as answers.

RadGrid ClientEvents OnRowClick

3 Answers 625 Views
Documentation and Tutorials
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 02 Jul 2015, 07:18 PM

Hello,

 I have a requirement to allow client side selection of a row using RadGrid.

 I have a parent form that opens a child form using javascript window.open.  I want the child form to pass back a value in a selected row in the grid.

I have set the following:

                    <ClientSettings EnableRowHoverStyle="true">
                        <Selecting AllowRowSelect="True" />
                        <ClientEvents OnRowClick="MyJavascriptFunction()" />
                    </ClientSettings>

The problem is the OnRowClick event is fired on load of the grid, but not on RowClick.  I've tried OnRowDblClick, OnRowSelected all with the same result.

Please help.

Thank you,

Tim Inouye

3 Answers, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 03 Jul 2015, 11:24 AM
Hi Tim,

In order to attach properly the desired function as a handler for the target event, you have to pass only its name as a string (without brackets). Defining a handler with brackets will call the function whenever this part of the code is read, so changing the given code in the following way should allow you to achieve the target scenario:
<ClientSettings EnableRowHoverStyle="true">
    <Selecting AllowRowSelect="True" />
    <ClientEvents OnRowClick="MyJavascriptFunction" />
</ClientSettings>

Regards,
Vessy
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
Tim
Top achievements
Rank 1
answered on 03 Jul 2015, 02:34 PM

Vessy,

Thank you, that solves the row click problem I was having.

Can you provide me a code snippet that allows me to access an element in the clicked row.  I have tried using get_selectedItems and get_gridDataItem with no success.

I'm trying to get a PO number out of the selected row.

Thanks in advance for all your help.

Tim Inouye

0
Vessy
Telerik team
answered on 08 Jul 2015, 11:47 AM
Hi Tim,

You can get reference to the clicked data item in the Grid, through the arguments of the RowClick client-side event:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
    <ClientSettings EnableRowHoverStyle="true">
        <Selecting AllowRowSelect="True" />
        <ClientEvents OnRowClick="MyJavascriptFunction" />
    </ClientSettings>
</telerik:RadGrid>
<script>
    function MyJavascriptFunction(grid, args) {
        var dataItem = args.get_gridDataItem();
        console.log(dataItem);
    }
</script>

You can also find details on all methods available in the RowClick event's argument object in it help article: RadGrid OnRowClick.

Regards,
Vessy
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
Tags
Documentation and Tutorials
Asked by
Tim
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Tim
Top achievements
Rank 1
Share this question
or