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

[Solved] Issues with double click on telerik grid row

3 Answers 47 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.
Murali
Top achievements
Rank 1
Murali asked on 06 May 2011, 01:41 PM
I am trying to call some controller action on double click of a MVC grid.
I have the following code:

<

 

 

script type="text/javascript">

 

 

 

function onLoad() {

 

 

$(

 

'tr', this).live('dblclick', function (e) {

 

 

alert(

 

"dblclcik");

 

 

 

 

var $tr = $(this);

 

 

alert($tr.text());

 

 

 

var $table = $tr[0].cells[0].innerHTML;

 

 

 

 

var $searchid = $tr[0].cells[1].innerHTML;

 

 

alert(

 

"table id:" + $table);

 

 

alert(

 

"search id:" + $searchid);

 

 

 

 

})

 

}

</

 

 

script>

 




@model

 

IEnumerable<CdcSoftware.Pivotal.ThinClient.Common.ViewBag.SearchDescriptionsViewModel>

 

 

 

 

@(Html.Telerik().Grid(Model)

 

.Name(

 

"SearchesGrid")

 

 

.ClientEvents(events => events

 

.OnLoad(

 

"onLoad"))

 

 

.Columns(columns =>

 

{

 

 

 

columns.Bound(o => o.TableId).Visible(

 

false);

 

 

columns.Bound(o => o.SearchID).Visible(

 

false);

 

 

columns.Bound(o => o.Name);

 

 

 

if (ViewData["AllSearches"].ToString() != "false") columns.Bound(o => o.ListType);

 

 

columns.Bound(o => o.Permission);

 

columns.Bound(o => o.CreatedByEmployeeName);

 

 

 

 

 

})



I need to read the valus of my tableID and SearchId fields in my double click event and pass it to a controller action. I donot want to display these fields on the grid.
The problem that I am facing is that If I set the Visible to false then the data cannot be read in the double click event.
If I make them hidden, (columns.Bound(o => o.TableId).Hidden(false)) then sorting is not working properly. Data is going haywire.
I also cannot add these columns to the end and make them hidden becuase some of the columns are bound in a conditional manner and hence the ordinal may not always be the same.
What is the resolution to this?

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 06 May 2011, 01:49 PM
Hi Murali,

 The only workaround I can suggest in this case is to use hidden fields in some of your existing columns in order to store the required properties. To do so use the Template of the column:

columns.Bound(o => o.Name).Template(o => 
{
    %>  
    <%= Html.HiddenFor(o => o.SearchID) %>
    <%= o.Name %>
});

Then you can get the value from the hidden field:

var $tr = $(this);
var searchID = $tr.find("input[name=SearchID]").val();

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
Murali
Top achievements
Rank 1
answered on 06 May 2011, 02:05 PM
Is this a razor syntax? This seems to give some errors with razor engine
0
Atanas Korchev
Telerik team
answered on 06 May 2011, 02:11 PM
Hi Murali,

 No, this is WebForms syntax. The Razor syntax should be like this:

columns.Bound(o => o.Name).Template(
@<text>
     @Html.Hidden("SearchID", @item.SearchID)
     @item.Name
</text>);

All the best,
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
Tags
Grid
Asked by
Murali
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Murali
Top achievements
Rank 1
Share this question
or