0

我在 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;
}
4

1 回答 1

0

我不知道为什么它确实隐藏了页脚中的分页,但我设法让它工作。不知何故,它只在我想隐藏第一列时隐藏页脚。所以不要使用:

table th:first-child, table td:first-child {
  display: none;
}

我用了:

table td:nth-child(10), table th:nth-child(10) {
  display: none;
}

现在它工作得很好。在表中有一个隐藏列的原因是当我单击整行时使用它:

$(function () {
var tr = $('#MainTable').find('tbody tr');
tr.live('hover', function () {
    $(this).toggleClass('clickable');
  }).live('click', function () {

      location.href = 'Whut/Details/' + $(this).find('td:nth-child(10)').text();

  });
});
于 2013-11-08T08:39:09.660 回答