保持表标题在MVC中固定

时间:2014-02-06 09:56:08

标签: asp.net-mvc razor-2

我有一个表,我需要保持标题固定。该表的代码如下:

@Html.Grid(Model).Columns(column =>
{
     column.For(m => m.Id).Attributes(@class => "HideColumn").HeaderAttributes(@class => "HideHeader");                                   
     column.For(m => m.HolidayName).Named("Holiday Name").Attributes(@style => "width:300px;");
     column.For(m => m.HolidayDetails).Named("Holiday Details ").Attributes(@style => "width:300px;");
     column.For(m => m.Status).Named("Status").Attributes(@style => "width:200px;"); 
}

怎么做?提前致谢。 :)

3 个答案:

答案 0 :(得分:3)

MVC中的网格将在客户端呈现为普通的HTML表格(至少在我的理解中,您正在使用像Grid.MVC这样的MVC Grid Nugets)。因此,您可以使用任何HTML Table Fixed标头JQuery插件来修复标题。

您拥有的一些选项是 -

JQuery FreezeHeader,您可以在其中使用 -

 $(document).ready(function () {
            $("#tableid").freezeHeader();
        })

还有一些选项 - Fixed Header TableSticky Table Headers等。

答案 1 :(得分:1)

您可以在脚本部分使用此代码:

  $(document).ready(function () {
                $('#yourTableId').floatThead({
                    top: $('.topbar').height(),
                    autoReflow: true,
                    zIndex: 1
                });
    });

答案 2 :(得分:0)

别忘了添加

<script src="/path/to/jquery.freezeheader.js"></script>

- )