ASP.NET mvc hiding webgrid columns
ASP.NET mvc hiding webgrid columns
我的cshtml文件接收模型内的一些bool值(+数据构建webgrid)。根据bool值,一些webgrid列必须显示和隐藏,例如我有:Name
, Surname
, Job
列在webgrid,但我有SurnameBool = 0
,这意味着只有Name
和Job
列必须显示。我曾尝试使用其他答案的代码,但不幸的是,我是JavaScript新手,所以请告诉我如何在webgrid中添加css display : none
属性到列,基于@if(ColumnNameBool)
结果。
WebGrid grid = new WebGrid(item2.ListOfWorkData, canSort: false, rowsPerPage: 15);
<div id="divWebGrid" class="row">
@if (item2.ListOfWorkData.Any())
{
@grid.GetHtml(
tableStyle: "table",
headerStyle: "table_HeaderStyle",
footerStyle: "table_PagerStyle",
rowStyle: "table_RowStyle",
alternatingRowStyle: "table_AlternatingRowStyle",
selectedRowStyle: "table_SelectedRowStyle",
columns: grid.Columns(
grid.Column("ProjectName", @Resources.Localization.project, format: @<text>
@if (Model.ColumnsNeeded.ProjectNameBool)
{
<span class="display-mode"><label id="ProjectNameLabel">@item.ProjectName</label></span>
}
</text>,style : "hidden-column"),
grid.Column("Activity", @Resources.Localization.activity, format: @<text>
@if (Model.ColumnsNeeded.ActivityBool)
{
<span class="display-mode"><label id="ActivityLabel">@item.Activity</label></span>
}
</text>, style: "p60"),
grid.Column("ProjectEndDate", @Resources.Localization.start_date, format: @<text>
@if (Model.ColumnsNeeded.ProjectStartDateBool)
{
<span class="display-mode"><label id="ProjectStartDate">@item.ProjectStartDate</label></span>
}
</text>, style: "p60"),
grid.Column("ProjectEndDate", @Resources.Localization.end_date, format: @<text>
@if (Model.ColumnsNeeded.ProjectEndDateBool)
{
<span class="display-mode"><label id="ProjectEndDate">@item.ProjectEndDate</label></span>
}
</text>, style: "p60")
)
)
}
你应该创建一个null来源的网格:
WebGrid grid = new WebGrid<Your item type>(null, canSort: false, rowsPerPage: 15);
用source:
绑定你的网格grid.Bind(item2.ListOfWorkData, rowCount: <total row count>, autoSortAndPage: false);
根据columnnamepool值创建列集:
var gridColumns = new List<WebGridColumn>();
@if(ColumnNameBool)
{
gridColumns.Add(grid.Column("ProjectName",
@Resources.Localization.project, format: @<text>
@if (Model.ColumnsNeeded.ProjectNameBool)
{
<span class="display-mode">
<label id="ProjectNameLabel">
@item.ProjectName</label>
</span>
}
</text>,style : "hidden-column"));
)
//... add other required columns here
}
else
{
//create here another list of columns that required
gridColumns.Add(...);
}
最后将列列表分配给grid:
@grid.GetHtml(<styles>, columns: gridColumns.ToArray());
相关文章:
- jTweetsAnywhere in 3 columns
- Webgrid ajax call MVC 5
- 从剑道ui网格中删除Columnmenu.columns
- 从Kendo中的columns.filterable.cell.template函数访问列字段名
- 在部分视图内渲染的WebGrid将引发“;“jQuery未定义”,当尝试执行基于ajax的分页或过滤时
- filled ExtJs columns json
- 为什么我的点击事件在点击对 WebGrid 进行排序后没有注册
- Webgrid寻呼机在隐藏列Mvc4后消失了
- 重新加载 w2ui 的 grid.columns.editable.items 如果字段是组合框
- 如何使用javascript从webgrid获取id
- equal height columns
- Webgrid需要使用MVC中的新内容进行更新
- MVC Webgrid,javascript在排序和分页后停止工作
- Flexigrid columns groups
- HTML、WebMatrix、Razor等处理WebGrid的新手
- MVC3中使用ajax刷新Webgrid
- jquery函数来隐藏webgrid列
- 在webgrid中调用javascript
- MVC webgrid column width?
- ASP.NET mvc hiding webgrid columns