This question is locked. New answers and comments are not allowed.
Hi,
I've been working on this issue for a few days now but have not been able to find a solution. I am supplying the grid with a data table that is created elsewhere. Effectively the user is creating a table with custom columns, thus I cannot create a model and with the columns specified. The column names and data types are deferred from the data table at runtime and the columns are auto generated. However within the data table there are always two fields: 'Rank' and 'RankId'.
Rank is a string value
RankId is a numerical listing the position of rank.
I would like to display the 'Rank' value but use the 'RankId' numerical value for sorting etc. This is not a huge issue as I can use client templates to use the 'Rank' column instead of the 'RankId'. However client templates are of course only applied when an ajax call is made. Here's the view code
One solution is to create the server template - and I've tried but can't seemed to get it to work. On thing I did try was
;
but couldn't get this or any variation to work.
Another solution would be to not load the data on the page load, and have an ajax call when the page loads (thus applying the client side templating) - while I know this is possible by not supplying data to the grid, you still have to supply some kind of model (in order for the columns to be deferred), the problem is I can't do this as the data table is generated on the fly.
Any help would be greatly appreciated.
Thanks,
I've been working on this issue for a few days now but have not been able to find a solution. I am supplying the grid with a data table that is created elsewhere. Effectively the user is creating a table with custom columns, thus I cannot create a model and with the columns specified. The column names and data types are deferred from the data table at runtime and the columns are auto generated. However within the data table there are always two fields: 'Rank' and 'RankId'.
Rank is a string value
RankId is a numerical listing the position of rank.
I would like to display the 'Rank' value but use the 'RankId' numerical value for sorting etc. This is not a huge issue as I can use client templates to use the 'Rank' column instead of the 'RankId'. However client templates are of course only applied when an ajax call is made. Here's the view code
Html.Telerik().Grid(Model.DataTable)
.Name("RegisterTable")
.DataBinding( bind => bind.Ajax().Select("_ViewAjaxBinding", "Registers", new { registerId = Model.RegisterId}))
.Columns(columns =>
{
columns.AutoGenerate(column =>
{
if (column.Member == "RankId")
{
---HERE'S WHERE I'D LIKE TO PUT THE SERVER TEMPLATE
column.Title = "Rank";
column.ClientTemplate = "<#= Rank#>";
}
if( column.Member == "Rank" ){
column.Visible = false;
}
});
})
.Render();
One solution is to create the server template - and I've tried but can't seemed to get it to work. On thing I did try was
column.template = ( t => t.Row["Rank"].ToString() )
but couldn't get this or any variation to work.
Another solution would be to not load the data on the page load, and have an ajax call when the page loads (thus applying the client side templating) - while I know this is possible by not supplying data to the grid, you still have to supply some kind of model (in order for the columns to be deferred), the problem is I can't do this as the data table is generated on the fly.
Any help would be greatly appreciated.
Thanks,