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
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.
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
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.
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
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.
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 Integer) As 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.
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
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.
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; |
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.
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
var grid = $(this).data('tGrid');
Regards, Chris$('.t-grid-content tr:not(.t-grouping-row)', this).live('dblclick', function (e) { var $tr = $(this); grid.editRow($tr); })