javascript - 为什么表格不能拉伸(stretch)到 100% 宽度

标签 javascript jquery html css jqgrid

enter image description here

上图,左边是 Accordion ,右边是内容部分(表格内) 我关心的是内容部分(右侧)为什么表格不是 100% 宽度?而其顶部的标题会扩展到整个页面宽度。下面给出了我的 content 代码。

var i=0;
var filesystem=[];
$(xml).find('file').each(function(){ 
    //console.info($(this).attr('total')+", "+$(this).attr('free')+", "+$(this).attr('used')+", "+$(this).attr('percentage'));
    var row={};
    row.id=i++;
    row.total=$(this).attr('total');
    row.free=$(this).attr('free');
    row.used=$(this).attr('used');
    row.percentage=$(this).attr('percentage');
    filesystem.push(row);
});


$('#detailTable').empty();
$('<div width="100%">')
.attr('id','diskUsageSpan')
.html('<div class="titleBlue">Configuration&gt;System&gt;Disk Usage</div>'+
        '<table id="list1" width="100%"></table>'+
        '<div id="gridpager"></div>'+
    '</div>')        
.appendTo('#detailTable');    


jQuery("#list1").jqGrid({
    datatype: "clientSide",
    height: 250,
       colNames:['id','Total Space','Free Space', 'Used Space', 'Used Percentage'],
       colModel:[
           {name:'id',index:'id', width:90, align:"right"},
           {name:'total',index:'total', width:90, align:"right"},
           {name:'free',index:'free', width:90, align:"right"},
           {name:'used',index:'used', width:90, align:"right"},
           {name:'percentage',index:'percentage', width:120, align:"right"}
       ],
       pagination:true,
       pager : '#gridpager',
       rowNum:10,
    viewrecords: true,
    gridview: true,
    edit:false,
    add:false,
    del:false

});


for(var i=0;i<filesystem.length;i++)
    jQuery("#list1").jqGrid('addRowData',i+1,filesystem[i]);

jQuery("#list1").setGridParam({rowNum:10}).trigger("reloadGrid");

最佳答案

您可以使用 height: 'auto'scrollOffset:0 jqGrid 选项来解决这个问题。原因是网格宽度的计算方式。它并不完美,总是为滚动条保留一些额外的位置。

在某些情况下也可以使用其他选项,如 autowidth:trueshr​​inkToFit:false

关于javascript - 为什么表格不能拉伸(stretch)到 100% 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6395208/

相关文章:

javascript - youtube如何使用ajax

javascript - 源自 JS RegExp

jquery - 从 jQuery 的多选下拉列表中取消选择所有元素

javascript - 如何解决 "NetworkError: 404 Not Found - http://localhost:50765/Scripts/jquery-1.5.1.min.js"错误

php - 如何使用ajax在codeigniter中上传图片

javascript - 如何减少替代样式表的加载时间?

html - 获取页脚到页面底部 Bootstrap

javascript - ng-click 在第一次单击后不起作用(嵌入指令)

javascript - 计算 div 内填充输入的百分比

javascript - 比较运算符和逻辑运算符有什么区别?