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

Double-click and Right-click event

10 Answers 362 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Christopher Ronak
Top achievements
Rank 1
Christopher Ronak asked on 17 Mar 2010, 10:13 PM
Is there a way to catch a double-click and right-click event on the asp.net mvc grid?

Thanks!

Chris

10 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 18 Mar 2010, 09:41 AM
Hello Christopher Ronak,

There is no out of the box support currently. However it is very easy to implement those using jQuery:

<%= Html.Telerik().Grid(Model)
     .Name("Grid")
     .ClientEvents(events => events.OnLoad("onLoad"))
%>


<script type="text/javascript">
function onLoad() {
    $('tr', this).live('dblclick', function(e) {
        var $tr = $(this);
        alert('double click ' + $tr.text());
    })
   .live('contextmenu', function(e) {
       // prevent the browser context menu from showing
       e.preventDefault();
       var $tr = $(this);
       alert('context menu ' + $tr.text());
   });
}
</script>


Regards,
Atanas Korchev
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
Rob Schoenaker
Top achievements
Rank 1
answered on 09 Apr 2010, 10:08 AM
I implemented double click support natively on the grid. Is there a place I can send my changes for consideration?
0
Atanas Korchev
Telerik team
answered on 09 Apr 2010, 10:09 AM
Hi Rob Schoenaker,

Right now there isn't but you can post your code in this forum thread.

Regards,
Atanas Korchev
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
Rob Schoenaker
Top achievements
Rank 1
answered on 09 Apr 2010, 10:20 AM
Changes to individual files below.

telerik.gris.js
        if (this.selectable)  
            $('tr:not(.t-grouping-row)', this.$tbody[0]).live('click', $t.delegate(this, this.rowClick))  
                .live('dblclick', $t.delegate(this, this.rowDblClick)) // ROBS 2010-04-08  
                .live("mouseenter", $t.hover)  
                .live("mouseleave", $t.leave); 
        $t.bind(this, {  
            error: this.onError,  
            dataBinding: this.onDataBinding,  
            dataBound: this.onDataBound,  
            rowSelected: this.onRowSelected,  
            rowDoubleClicked: this.onRowDoubleClicked,  // ROBS 2010-04-08  
            rowDataBound: this.onRowDataBound,  
            load: this.onLoad  
        }); 
    $t.grid.prototype = {  
 
        rowClick: function(e, element) {  
            $(element).addClass('t-state-selected')  
                      .siblings().removeClass('t-state-selected');  
            if (this.onRowSelected)  
                $t.trigger(this.element, 'rowSelected', { row: element });  
        },  
 
        // ROBS 2010-04-08  
        rowDblClick: function (e, element) {              
            $(element).addClass('t-state-selected')  
                      .siblings().removeClass('t-state-selected');  
            if (this.onRowDoubleClicked)  
                $t.trigger(this.element, 'rowDoubleClicked', { row: element });  
        },  
 


Grid.cs
...  
            objectWriter.Append("onRowSelected", ClientEvents.OnRowSelected);  
            objectWriter.Append("onRowDoubleClicked", ClientEvents.OnRowDoubleClicked); // ROBS 2010-04-08  
            objectWriter.Append("onDataBound", ClientEvents.OnDataBound);  
... 

GridClientEvents.cs
        // ROBS 2010-04-08  
        public Action OnRowDoubleClicked  
        {  
            get;  
            set;  
        } 

GridClientEventsBuilder.cs
        // ROBS 2010-04-08 start  
        /// <summary>  
        ///  Defines the name of the JavaScript function that will handle the the OnRowDoubleClicked client-side event.  
        /// </summary>  
        /// <param name="onLoadHandlerName">The name of the JavaScript function that will handle the event.</param>  
        /// <example>  
        /// <code lang="CS">  
        ///  &lt;%= Html.Telerik().Grid(Model)  
        ///             .Name("Grid")  
        ///             .ClientEvents(events => events.OnRowDoubleClicked("onRowDoubleClicked"))  
        /// %&gt;  
        /// </code>  
        /// </example>  
        public GridClientEventsBuilder OnRowDoubleClicked(string onRowDoubleClickedHandlerName)  
        {  
            Guard.IsNotNullOrEmpty(onRowDoubleClickedHandlerName, "onRowDoubleClickedHandlerName");  
 
            events.OnRowDoubleClicked = HandlerAction(onRowDoubleClickedHandlerName);  
 
            return this;  
        }  
 
        /// <summary>  
        /// Defines the inline handler of the OnRowDoubleClicked client-side event.  
        /// </summary>  
        /// <param name="onLoadAction">The action defining the inline handler.</param>  
        /// <example>  
        /// <code lang="CS">  
        ///  &lt;% Html.Telerik().Grid(Model)  
        ///            .Name("Grid")  
        ///            .ClientEvents(events => events.OnRowDoubleClicked(() =>  
        ///            {  
        ///                 %&gt;  
        ///                 function(e) {  
        ///                     //Error handling code  
        ///                 }  
        ///                 &lt;%  
        ///            }))  
        ///            .Render();  
        /// %&gt;  
        /// </code>  
        /// </example>  
        public GridClientEventsBuilder OnRowDoubleClicked(Action onRowDoubleClickedAction)  
        {  
            Guard.IsNotNull(onRowDoubleClickedAction, "onRowDoubleClickedAction");  
 
            events.OnRowDoubleClicked = onRowDoubleClickedAction;  
 
            return this;  
        }  
 

That should be it. I can provide a zip file with the changes.
0
Atanas Korchev
Telerik team
answered on 09 Apr 2010, 11:07 AM
Hello Rob Schoenaker,

Thank you! This would suffice. I hope we can squeeze that in the next release.

I have updated your telerik points as a token of gratitude.

Regards,
Atanas Korchev
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
Adam Haid
Top achievements
Rank 1
answered on 18 Nov 2010, 10:47 PM
Has this been implemented in any code releases yet?
0
Julián
Top achievements
Rank 1
answered on 23 Nov 2010, 03:03 PM
Hi,

This works fine :)

Is there a way of put the row in edit mode on double click event? Using this code?

Thanks!
0
Greg
Top achievements
Rank 1
answered on 09 Dec 2010, 06:50 PM
I don't think this solution works with the latest version of the MVC control suite (2010.3.1110). I can't seem to find the JavaScript files reference or even similar lines of code any where in the Telerik JS.

Is there no native client side event handling for the grid? If there isn't this is probably going to be a deal breaker for us. :(
0
Rosen
Telerik team
answered on 10 Dec 2010, 08:50 AM
Hi Greg,

You may refer to this forum thread for more details on how to implement edit on row double-click.

All the best,
Rosen
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
Greg
Top achievements
Rank 1
answered on 10 Dec 2010, 02:33 PM
Not really looking to edit the cell or row but fire an event. I think that source might get me where I need to go.
Tags
Grid
Asked by
Christopher Ronak
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Rob Schoenaker
Top achievements
Rank 1
Adam Haid
Top achievements
Rank 1
Julián
Top achievements
Rank 1
Greg
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or