简体   繁体   English

使用Bootstrap在ASP.NET MVC中布局jQGrid

[英]Layout a jQGrid in ASP.NET MVC with Bootstrap

I have this line of code in _Layout.cshtml 我在_Layout.cshtml中有这行代码

<div class="row">
    <div class="col-md-10">
        @RenderBody()
    </div>
</div>

Every view in the project uses that file and they all render fine. 项目中的每个视图都使用该文件,并且它们都可以正常渲染。

There an issue with one particular view which uses DataTables and jQGrid and it has this code in it: 一个使用DataTables和jQGrid的特定视图存在问题,并且其中包含以下代码:

<div style="margin-bottom: 10px">
    <h3 style="display: inline">Blah ...</h3>
</div>

<div>
    <table style="width:100%" id="updateHistoryTable" class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>
                    Id
                </th>
                <th>
                    Name
                </th>
                <th>
                    Join Date
                </th>
                <th>
                    End Date
                </th>
                <th>
                    Status
                </th>
                <th>
                    History
                </th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>
<br />
<br />
<div id="statusHistoryDiv">
        <table id="statusHistoryTable"></table>
    </div>
</div>

JS to setup the jQGrid: JS设置jQGrid:

$("#statusHistoryTable").jqGrid(
        {
            datatype: "local",
            data: statusHistoryData,
            colNames: ["Id", "Name", "Date Time", "Status"],
            colModel: [
                { name: "Id", key: true },
                { name: "Name" },
                { name: "DateTime" },
                { name: "Status", width: "150px" }
            ],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#pager2',
            sortname: 'Id',
            viewrecords: true,
            sortorder: "desc",
            caption: "Status History",
             ....
}

I tried width: null but that makes the grid show nothing. 我试过width:null,但这使网格什么也没显示。

The DataTables grid renders fine but the jQGrid renders leaving out a negative space towards the right. DataTables网格可以很好地渲染,但jQGrid可以渲染向右的负空间。

How do I get the second grid the same size as the first one without the -ve space? 如何在没有-ve空间的情况下使第二个网格与第一个网格大小相同?

在此处输入图片说明

First of all you use wrong value width: "150px" for Status column. 首先,您使用了错误的值width: "150px" Status width: "150px" The width value should number. 宽度值应为数字。 So the correct value will be width: 150 . 因此正确的值应该是width: 150 On the other side the default value for width is already 150 (see the value in "Default" column in the table ). 另一方面, width的默认值已经是150(请参阅中“默认”列中值)。 So you can see that the width of the grid which you created is 650px (4*150 for 4 columns and 30 for the column created because of using rownumbers: true option). 因此,您可以看到创建的网格的宽度为650px(4 rownumbers: true 4 * 150,创建的rownumbers: true 30 *,因为使用了rownumbers: true选项)。 To increase the width you can use autowidth: true option additionally. 要增加宽度,您可以另外使用autowidth: true选项。 It will get the width of outer div (div#statusHistoryDiv) and extend the width of columns proportionally to width values of columns (the same 150 value in your case). 它将获取外部div的宽度(div#statusHistoryDiv),并与列的width值(在您的情况下为150相同)成比例地扩展列的width You can add resize event handler which calls setGridWidth if you like to make the grid responsive. 您可以添加resize事件处理程序,如果您希望使网格响应,则调用setGridWidth See the answer for the simplest implementation. 有关最简单的实现,请参见答案 If you need support IE8 then you would write the code a little longer, but I'm not sure whether you need it. 如果您需要支持IE8,则可以编写更长的代码,但是我不确定是否需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM