我在 Mvc4 中有一个 Webgrid,我想在其中隐藏一列。问题是当我隐藏该列时,分页正在消失,我不知道为什么。
我的网络网格看起来像这样:
@{
var grid = new WebGrid(canPage: true, canSort: true, rowsPerPage: 10, ajaxUpdateContainerId: "gridcontent");
grid.Bind(source: Model.Projects, rowCount: Model.RowCount, autoSortAndPage: false);
grid.PageIndex = Model.ProjectPage;
grid.SortColumn = Model.SortColumn;
grid.SortDirection = Model.SortDirectionForColumn;
}
<div id="gridcontent">
@grid.GetHtml(
fillEmptyRows: false,
tableStyle: "webgrid",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
rowStyle: "webgrid-row-style",
mode: WebGridPagerModes.All,
htmlAttributes: new { id = "MainTable" },
columns: grid.Columns(
grid.Column("VsuProjectId", "Project Id"),
grid.Column("ProjectName", " Project " + VsuWebPortal.Models.WebgridHelper.SortDirection(null, ref grid, "ProjectName"), style: "columnWidth"),
grid.Column("CountryName", "Country", style: "columnWidth"),
grid.Column("CustomerName", "Customer Name" style: "columnWidth"),
grid.Column("CRMId", "CRM Id", style: "columnWidth"),
grid.Column("MainProjectVersion", "Project Version", canSort: false, style: "columnwswithNotSortable")
))
隐藏列的javascript函数是;
function hideColumnColorRow(column) {
$('td:nth-child(' + column + '),th:nth-child( ' + column + ')').hide();
}
我也尝试过使用 Css 来实现,它确实隐藏了该列,但在分页时给出了相同的结果。
table th:first-child, table td:first-child {
display: none;
}