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

Add an event handler from the client-side

2 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 01 Apr 2011, 12:54 PM
Is it possible to add an event handler to the grid (e.g. for the RowSelected event) from the client-side javascript?

Example:

<telerik:RadGrid ID="grid" runat="server" ...>
    ...
    <ClientSettings>
        <ClientEvents OnGridCreated="gridCreated" />
    </ClientSettings>
</telerik:RadGrid>
...
<script>
function gridCreated(sender, eventArgs) {
    if (someCondition) {
        //
        Can I add function rowSelected() as a handler to
        the grid's OnRowSelected event?
        //
    }
}
 
function rowSelected(sender, eventArgs) {
    // do stuff
}

I tried calling the grid's add_rowSelected() function, but couldn't get it to work.
Thanks for your help.

-Martin

2 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 06 Apr 2011, 10:12 AM
Hello Martin,

The desired functionality can be easily achieved with the following code:
function GridCreated(sender, eventArgs) {
    if (condition) {
        sender.add_rowSelected(RowSelected);
    }
}
 
function RowSelected(sender, eventArgs) {
    //...
}

I hope this helps.

Greetings,
Mira
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Martin
Top achievements
Rank 1
answered on 07 Apr 2011, 08:23 AM
Thanks Mira, that's what I was looking for!
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Mira
Telerik team
Martin
Top achievements
Rank 1
Share this question
or