开发者

show dynamically selected columns in asp.net mvc grid at runtime

开发者 https://www.devze.com 2023-01-15 12:46 出处:网络
I have an asp.net MVC application where I am using telerik grid to show the data/records.I am using the Entity Mode开发者_StackOverflow中文版l.

I have an asp.net MVC application where I am using telerik grid to show the data/records.I am using the Entity Mode开发者_StackOverflow中文版l.

My requirement is that sometime I want to show only some of the columns specified at the runtime/may the user select. How do I bind View with only those columns as selected by the user . Initially view is binded with Model class with all columns .

Is there any other way other than telerik to show the customized columns as selected by the user then it will be also OK .


You could customize the columns that are shown using the Columns method. You need to have the information about which columns need to be shown in the view model so that you can at runtime select the columns to show:

<%= Html.Telerik()
        .Grid(Model.Customers)
        .Name("Grid")
        .Columns(columns =>
        {
            if (Model.IsShowFirstName)
            {
                columns.Bound(customer => customer.FirstName);
            }
            if (Model.IsShowLastName)
            {
                columns.Bound(customer => customer.LastName);
            }
        })
%>


<%= Html.Telerik() 
    .Grid(Model.Customers) 
    .Name("Grid") 
    .Columns(columns => 
    { 
        columns.Bound(customer => customer.FirstName).Visible(Model.IsShowFirstName); 
        columns.Bound(customer => customer.LastName).Visible(Model.IsShowLastName); 
    }) 
%>
0

精彩评论

暂无评论...
验证码 换一张
取 消