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

what is the GridColumnsettings<T>.Template intended use?

2 Answers 54 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.
John Yoo
Top achievements
Rank 1
John Yoo asked on 28 Mar 2011, 08:31 PM
How is one supposed to use the Template property on the GridColumnSettings<T> instances?
I could not find a way to affect the output in the grid HTML from the delegate assigned to the Template property, I am assuming there would be a way?
I assumed this property could be used to affect the html output from the Controller, just like the template column definitions can in the view.  Am I wrong about that?  Is intended for something else? 
If so, what is the "proper" way of achieving a template column from the Controller?

Having the code helps out a lot, so I took the initiative and added my own property, "InlineTemplate" (Func<T, object>) to the GridColumnSettings<T>, which is then assiged to the GridColumnBase<T>.InlineTemplate by the GridColumnGenerator<T>.CreateBoundColumn() method.  It works like a charm, and does what I expected the Template property would do, but I am hesitant to deploy this solution into production.
Is this the right way of doing it?  If so, can this be integrated in the release code, so that going forward we can use the release assemblies instead of our custom builds?

2 Answers, 1 is accepted

Sort by
0
Chandra Thumburu
Top achievements
Rank 1
answered on 31 Oct 2011, 05:00 PM
I would appreciate if some one could answer the above question.
0
Atanas Korchev
Telerik team
answered on 31 Oct 2011, 05:54 PM
Hello Chandra Thumburu,

 The Template property will set the template of the column. Here is how to set it:

                new GridColumnSettings<EditableProduct>
                {
                    Member = "UnitPrice",
                    Width = "130px",
                    Format = "{0:c}",
                    Template = (p) =>
                        {
                            this.Response.Write("<strong>" + p.UnitPrice + "</strong>");
                        }
                },

There is a catch though. This will only work if the grid is output via Render():

<% Html.Telerik().Grid()
        .Render();
%>

Also this would work only in WebForms view engine. If used with Razor the template column values would appear on the top of the page because Razor does not rely on the Response object for outputting values.

Greetings,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
John Yoo
Top achievements
Rank 1
Answers by
Chandra Thumburu
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or