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

[Solved] Row Double Click Event - Client

12 Answers 283 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.
Joao Cardoso
Top achievements
Rank 1
Joao Cardoso asked on 09 Jun 2010, 11:14 AM

I'm trying to figure out how can I detect the double click event, client side, the same way we can dtect onRowSelected. What I'm trying to do is to open a popup window to show the contents of one property of the row data item. For example imagine I have a customer list, and I have an hidden notes field on the Grid that I want to show on a double click event.

At the same time I would also love to see an example on a actionlink. For instance, when double click on a row, invoke the edit view for the record.

Any pointers are very welcome. C# or VB.NET :)

Cheers

12 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 09 Jun 2010, 11:23 AM
Hi Joao Cardoso,

You can check this related forum post.

To enter edit mode use the editRow JavaScript method:

function onLoad() {
   var grid = $(this).data('tGrid');
   $('tr', this).live('dblclick', function(e) {
        var $tr = $(this);
        grid.editRow($tr);
    })
}

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
Joao Cardoso
Top achievements
Rank 1
answered on 09 Jun 2010, 11:38 AM

Hi Atanas,

Thats a great tip. Can it be adapted to for instance, show a jQuery modal with the contents of a hidden column? 

Another example I was looking for is a way to double lick a row and be directed to the an edit action, instead of in place editing. I don't want to use the grid edit, because I have a view for that.

Thanks again for your help

Cheers

0
Atanas Korchev
Telerik team
answered on 09 Jun 2010, 12:44 PM
Hi Joao Cardoso,

You can execute whatever code you like in the dblclick event handler. Do what you need - show popups, open new windows etc.

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
Joao Cardoso
Top achievements
Rank 1
answered on 09 Jun 2010, 01:21 PM
Hi Atanas,

Thanks again.

Final question.... is it possible to get the contents of an hidden column?

I'm using this code:

        function onLoad(e) {  
            var grid = $(this).data('DocumentosGrid');  
            $('tr'this).live('dblclick'function (e) {  
                var $tr = $(this);  
                var notes = $tr[0].all[4].innerHTML;  
                $("#ShowDialog").html(notes).dialog();  
            })  
        }  
 

But this way I can only access visible columns data. Any tips on how to get the contents of an hidden column?

Cheers

Joao Cardoso
0
Atanas Korchev
Telerik team
answered on 09 Jun 2010, 01:51 PM
Hi Joao Cardoso,

Try

$tr[0].cells[4].innerHTML

Also make sure the column is Hidden(true) instead of Visible(false). The latter causes the column to not be output in the HTML at all.

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
Joao Cardoso
Top achievements
Rank 1
answered on 09 Jun 2010, 01:52 PM

EDIT: Saw your reply after my post. I still prefer this way, because I dont have to load a huge a amount of data just do make it hidden on the grid. This is a notes field and can have lots of text... so using the json request its better as I just load the data I need. Your tip is also welcome and I«m sure I will find use to it. At least to hide the internal ID column :)

Found the solution :)

I may as well share it.

Basically what I did was to create a Method on my controller to retrieve the data I needed, in JSON.

Then on the client side I just invoke the method and get the data to be displayed.

Controller code:

Function GetNotes(ByVal id As IntegerAs ActionResult  
     Return Json(GetNotes(context, id), JsonRequestBehavior.AllowGet)  
End Function 

Note: GetNotes is a method that gets the notes field from an entity (i'm using Entity Framework btw).

View Code:

        function ShowMyDialog(data, textStatus) {  
            $("#ShowDialog").html(data).dialog({ width: 700, height: 600 });  
        }  
 
        function onLoad(e) {  
            var grid = $(this).data('DocumentosGrid');  
            $('tr', this).live('dblclick', function (e) {  
                var $tr = $(this);  
                var id = $tr[0].all[0].innerText;  
                jQuery.getJSON('/MyController/MyNotes/' + id, '', ShowMyDialog);  
            })  
        }  
 

Thanks for your pointers.

0
Joao Cardoso
Top achievements
Rank 1
answered on 09 Jun 2010, 05:17 PM
Well... I talked too soon.

This solution works great for a grid with no groups. As soon as I drag a column to the header to group by it, the above solution does not work anymore. I guess this has something to do with the jquery selector. Any tips on how to solve this one?

Thanks in advance

Cheers

João Cardoso
0
Atanas Korchev
Telerik team
answered on 10 Jun 2010, 07:45 AM
Hello Joao Cardoso,

Modify the selector to not include the grouping rows:

$('tr:not(.t-grouping-row)', this).live('dblclick', function (e) {  

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
Joao Cardoso
Top achievements
Rank 1
answered on 11 Jun 2010, 10:50 AM
Hi Atanas,

I found the problem. Its not related with exclusing the group rows but the fact that when we add a group the columns are increased by 1 for each column we add. So my ID instead of being on column 0, is now on column 1, or 2 and so forth, depending of the number of groups.

The way I'm accessing the column I want to get the id from is like this:
var $tr = $(this);  
var id = $tr[0].all[0].innerText; 

Is there a way to get on the onLoad event the number of columns by witch the grid is grouped by? So perhaps I would do something like:

var $tr = $(this);  
var id = $tr[0].all[NumberOfGroups].innerText; 

0
Atanas Korchev
Telerik team
answered on 11 Jun 2010, 10:59 AM
Hi Joao Cardoso,

grid.groups.length should return the number of groups.

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
Joao Cardoso
Top achievements
Rank 1
answered on 11 Jun 2010, 02:45 PM
Hi Atanas,

I didnt managed to get to access those properties in javascript on the OnLoad event so I decided to make a simpler solution.

This works if we assume that the first column has the ID. If its not the first column, then the script needs to be changed because it basically tries to find the first column with a value.

 function onLoad() {  
            $('tr:not(.t-grouping-row)'this).live('dblclick'function (e) {  
                var $tr = $(this); var i = 0;  
 
                while ($tr[0].all[i].innerText == '') {i++}  
                var id = $tr[0].all[i].innerText;  
 
                if (id != '') {  
                    jQuery.getJSON('/Process/GetNotes/' + id, '', ShowNotasDialog);  
                } else {  
                    ShowNotasDialog('Error !');  
                }  
 
            })  
        } 


Its no perfect by all means and I welcome a better solution. But for now its doing the job well.

Cheers
0
Chris
Top achievements
Rank 1
answered on 21 Apr 2011, 01:29 PM
Better to target only the content rows in the grid, otherwise double-clicking the headings produces very odd results (easily done when sorting columns by single-clicking the heading):

var
 grid = $(this).data('tGrid');
$('.t-grid-content tr:not(.t-grouping-row)'this).live('dblclick'function (e)
{
    var $tr = $(this);
    grid.editRow($tr);
})
Regards, Chris
Tags
Grid
Asked by
Joao Cardoso
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Joao Cardoso
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Share this question
or