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

Grid Dynamic Title from Grid model

1 Answer 281 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bapuy
Top achievements
Rank 1
bapuy asked on 25 Feb 2015, 09:10 AM
Hi There,

I would like to do dynamic columns using list item from MyModel, can i change the column "title" base on MyModel?

MyModel
{
     List<Item> Items;
}


Please refer to code below : 

@(Html.Kendo().Grid<MyModel>()
    .Name("gridStudentList")
    .Columns(columns =>
    {


        for (int i = 0; i < 3; i++)
        {

            columns.Bound(c => c.Items[i].Product).Title("Can i use Mymodel property here?").Filterable(false); 
            columns.Bound(c => c.Items[i].ProductPrice).Filterable(false); 
        }

    })
Thanks for your time. Regards,






1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 27 Feb 2015, 09:43 AM
Hello Bapuy,

The desired behavior is possible to achieve if you use auto-generated columns (i.e. no Columns() configuration at all). In this case the Grid will generate the column titles based on the data. You can define the column titles via data annotation attributes in the Model.

[DisplayName("Product name")]
public string ProductName
{
    get;
    set;
}



Regards,
Dimo
Telerik

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Tags
Grid
Asked by
bapuy
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or