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

寵の児 提交于 2019-12-11 03:57:35

问题


I have an asp.net MVC application where I am using telerik grid to show the data/records.I am using the Entity Model.

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 .


回答1:


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);
            }
        })
%>



回答2:


<%= 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); 
    }) 
%>


来源:https://stackoverflow.com/questions/3668086/show-dynamically-selected-columns-in-asp-net-mvc-grid-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!