RadGrid ClientEvents OnRowClick

4 posts, 0 answers
  1. Tim
    Tim avatar
    8 posts
    Member since:
    May 2015

    Posted 02 Jul 2015 Link to this post

    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

  2. Vessy
    Admin
    Vessy avatar
    1382 posts

    Posted 03 Jul 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tim
    Tim avatar
    8 posts
    Member since:
    May 2015

    Posted 03 Jul 2015 in reply to Vessy Link to this post

    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

  5. Vessy
    Admin
    Vessy avatar
    1382 posts

    Posted 08 Jul 2015 Link to this post

    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
Back to Top