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

[Solved] Column .Format question

4 Answers 136 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.
Salo Corgan
Top achievements
Rank 1
Salo Corgan asked on 11 Mar 2010, 06:03 PM
Hi there.

I'm trying to have the same generated content rendered with the page render, and when the grid is refreshed via ajax.

Battling a bit with the .Format() method.

Below works fine, I get my anchors.

column.Bound(x => x.ServiceCode).Format( 
                   Html.ActionLink("{0}", "MyAction") 
               ).Title("Id").Encoded(false); 

What I need however is this:

column.Bound(x => x.ServiceCode).Format( 
                   Html.ActionLink("{0}", "MyAction", new { id = x.Id }) 
               ).Title("Id").Encoded(false); 

How do I access other properties of my "x" object (such as .Id), as opposed to just {0}

Many thanks.

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 11 Mar 2010, 06:14 PM
Hello Salo Corgan,

You can try to use client-side templates. Here are links to the online demo and the help article.

All the best,
Georgi Krustev
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
Salo Corgan
Top achievements
Rank 1
answered on 11 Mar 2010, 06:16 PM
Thanks for the quick response Georgi , but the problem I found with client templates is that they only apply to your ajax request.
For every column, I'd have to provide a template for server side rendering, and then a client side template, if I wanted the page to load with content.

Is that correct?
0
Cranialstrain
Top achievements
Rank 1
answered on 12 Mar 2010, 12:53 AM
I have the same problem with .ClientTemplate so have reverted back to using .Format and sending back formatted HTML via Ajax. It's a real shame as I've been waiting for ClientTemplate for some time so that I can keep HTML formatting in the view. I'm also unsure if .ClientTemplate will support object properties such as <#= Customer.AddressLine1 #>, which would also be a requirement for me.

Ian
0
Alan Murphy
Top achievements
Rank 1
answered on 12 Mar 2010, 03:02 AM
The way i handle this situation is building my own divs in javascript using the properties off of the returned json object using the onRowDataBound event.  In the example below the getAddressDisplay function could return formatted divs with <a> tags or whatever you want.  I have found this to be easier to work than client templates.

    function onRowDataBound(e) {
        var row = e.row;
        var dataItem = e.dataItem;

        row.cells[1].innerHTML = getAddressDisplay(dataItem.AddressOne, dataItem.AddressTwo);
}
Tags
Grid
Asked by
Salo Corgan
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Salo Corgan
Top achievements
Rank 1
Cranialstrain
Top achievements
Rank 1
Alan Murphy
Top achievements
Rank 1
Share this question
or