I want to create a grid programatically in ASP.Net MVC, depending on the model and its values.
I looked through the samples, but could not see the one.
Can some one know me whether is it possible and if yes how?
Thanks,
Rahul Agashe
6 Answers, 1 is accepted
In order to achieve your goal you will need to use auto generated columns. Please review this online demo for more information.
Sincerely yours,
Georgi Krustev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
.Columns(columns =>
{
foreach (TelerikEvaluation.Customer lstRows in Model.Records)
{
int RowCount = 0;
columns.Add(c => c.EmpId).Title(lstRows.EmpId.ToString()).Filterable(
false).Sortable(false);
columns.Add(c => c.FirstName).Filterable(
false).Sortable(false);
RowCount++;
break;
}
})
Something like a wrapper over Telerik grid, which will accept a generic Type Model and render a grid as per the model.
I think that this is possible right now. Are you experiencing any difficulties creating columns programmatically?
Greetings,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I am trying to add columns using below code,
foreach (TelerikEvaluation.MetaDataInfo MetaDataRow in Model.MetaDataData)
{
columns.Add(c => c.GetType().GetProperty(MetaDataRow.PropertyName).GetValue(c,
null)).Title(MetaDataRow.PropertyHeader);
}
The problem is that Grid is displaying the Headers correctly, but the Rows render displayes data only from the Last Column in the For loop.
If I write Code to add multiple columns as below, grid is displaying records correctly,
columns.Add(c => c.EmpId);
columns.Add(c => c.FirstName);
columns.Add(c => c.LastName);
columns.Add(c => c.BirthDate);
Please see attached screen shot for clerification. Is it a bug or I need to change some of my code?
Unfortunately the grid does not support the following syntax for defining the column binding:
columns.Add(c => c.GetType().GetProperty(MetaDataRow.PropertyName).GetValue(c,
null))
While it is valid C# and may work on initial binding it would fail if you try to sort or page. The reason is that the MVC grid understand only simple C# expressions - only member access.
Regards,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.