This is a migrated thread and some comments may be shown as answers.
Using an Action URL for the Selection event
7 Answers 117 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nick
Top achievements
Rank 1
Nick asked on 14 Apr 2010, 01:14 AM
I'm trying to do something that to me, seems pretty simple but I can't seem to find the answer.

I have a database table full of Members, with a primay key is "Id". I'm rendering it using a view using the Grid control which is reachable via ~/members/index.
The behavior I am trying to achieve is when you click on a row to have it essentially query ~/members/details/{id goes here}

I tried using the client side select event but then I don't have access to the Url.Action() method to dynamically generate the URL. I can't do it as an inline handler because the method is not unique per row. I was trying to use the following line
.ClientEvents(e => e.OnRowSelected(() => {%> function(e) { window.location = "<%=Html.Action("Details", new { id = m.Id } ) %>" } <%}))  
 

Notice there is no way for it to resolve "m" to get the property "Id".

I had looked at a Command column, but on top of it being represented as a button instead of clicking on the row I can't seem to alter the Action link it seems to be using to query the server. It's defaulting to ~/members/index/{id goes here}

At this point I'm assuming I'm just going about this all wrong and am missing something obvious. Maybe a second set of eyes can point me in the right direction?

7 Answers, 1 is accepted

Sort by
0
IQworks
Top achievements
Rank 1
answered on 14 Apr 2010, 01:44 AM

Hi Nick,

       might give some ideas    

.ClientEvents(events => events.OnRowSelected("OnRowSelected"))  
 
/* This runs when a row is selected */  
     function OnRowSelected(e) {  
    location.href = "/Work/Index/?workindex=1&OtherParms=2";   
 } 
0
Nick
Top achievements
Rank 1
answered on 14 Apr 2010, 04:20 PM
Yeah I have seen that example in the demo applications, my problem is I need a means of dynamically generating the URL they may be sent to. The example detailing client side selection event is able to pull the ID of the row using something such as the following
var ordersGrid = $('#Orders').data('tGrid'); 
customerID = e.row.cells[0].innerHTML;  

But the example also included the Id as the first column, in my case the Id's are GUIDs and are not included as a column for output. Nor do I have access to the Url.Action() method for resolving the url to use.
0
IQworks
Top achievements
Rank 1
answered on 14 Apr 2010, 05:33 PM
Hi Nick, 
        This is what I see that your saying .... 
"The behavior I am trying to achieve is when you click on a row to have it essentially query ~/members/details/{id goes here}"
 "I can't seem to alter the Action link it seems to be using to query the server. It's defaulting to ~/members/index/{id goes here}"
then 
" in my case the Id's are GUIDs and are not included as a column for output. Nor do I have access to the Url.Action() method for resolving the url to use." 
       I have not done this without the id (or parm value) being an actual output column.  Are you saying this id is a generated GUID input column ? 
       Sorry I am not helping here.
thanks
0
Nick
Top achievements
Rank 1
answered on 14 Apr 2010, 06:07 PM
No it's not a generated column. The Id is the primary key for the member, it's not generated at runtime or anything like that.
With the Id being a GUID, it's not one of the columns I show in the grid for obvious reasons. So I don't know if the Id is even accessible on the client via Javascript or not.

If I cant find a solution, I may just submit a support ticket instead. I had thought to try the forums first if it was something trivial I was missing in my understanding of the control. But from the looks of it, that may not be the case.
0
IQworks
Top achievements
Rank 1
answered on 14 Apr 2010, 06:48 PM
Hi Nick,
   Not to confuse the issue, but if you post your entire grid code, another forum member may see something else? just a thought. 
   Good luck!
0
Nick
Top achievements
Rank 1
answered on 14 Apr 2010, 06:52 PM
I had thought that as well, but it is nothing too complicated so I had doubted it hid any sort of gem that might be the answer to my problem. Either way, this is my grid at the moment.
Html.Telerik().Grid<Member>() 
    .Name("Grid"
    .BindTo(Model) 
    .Columns(c => 
        { 
            c.Bound(m => m.CardNumber).Title("Card"); 
            c.Bound(m => m.LastName).Filterable(true).Template(m=> { %> <%=m.FirstName + " " + m.LastName%> <% }).Title("Name"); 
            c.Bound(m => m.Address).Filterable(false); 
            c.Bound(m => m.City).Filterable(false); 
            c.Bound(m => m.PostalCode).Filterable(false); 
            c.Bound(m => m.Province).Filterable(false); 
            c.Bound(m => m.Phone); 
        }) 
    .Pageable(p => p.PageSize(25)) 
    .Sortable(s => s.OrderBy(o => o.Add(m => m.CardNumber).Descending())) 
    .Filterable() 
    .Selectable() 
    .DataKeys(keys => keys.Add(m=>m.Id)) 
    .Render(); 

0
Stepney
Top achievements
Rank 1
answered on 15 Apr 2010, 02:53 PM
Hi Nick,

I have to do the exact same thing.

What I did was to include the Id as a column, but hide it.

Then attach two events to get at the id and to do the selection. Here is an example:

 

.Columns(columns => 
 
{  
 
columns.Bound(o => o.Id).Hidden(true);  
 
columns.Bound(o => o.Code).Width(60);  
 
columns.Bound(o => o.Description);  
 
})  
 
.ClientEvents(  
 
events => events  
 
.OnRowDataBound("onRowDataBound")  
 
.OnRowSelected("onRowSelected")  
 
)  
 

and for the event handlers:

<script type="text/javascript">  
 
    function onRowDataBound(e) {  
        ee.row.rowid = e.dataItem.Id;  
    }  
 
    function onRowSelected(e) {  
        var newloc = 'Product/Index/' + e.row.rowid;  
        document.location.href = newloc;  
    }                                               
</script> 

 

Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
IQworks
Top achievements
Rank 1
Nick
Top achievements
Rank 1
Stepney
Top achievements
Rank 1
Share this question
or