Dis*_*ame 16
不是直接但有可能......
如果您想要将整个网格的宽度设置为百分比,则可以使用autowidth属性,并将网格宽度设置为其父元素(即DIV)的宽度,并且该父元素可以设置它的百分比.
autowidth: true
Run Code Online (Sandbox Code Playgroud)
如果要按百分比设置列宽,可以使用shrinktofit,然后列宽值基本上是百分比.
shrinkToFit: true
Run Code Online (Sandbox Code Playgroud)
这些选项和许多其他选项可以在JQGrid 维基上找到
小智 16
它可以非常简单的方式:
$(document).ready(function(){
var pageWidth = $("#updatesList").parent().width() - 100;
$("#updatesList").jqGrid({
url:'quick_updates.php?action=loadUpdates'+"&request=ajax",
datatype: "json",
colNames:[table_heading_id, table_heading_products, table_heading_categories, table_heading_model, table_heading_availability, table_heading_weight, table_heading_quantity, table_heading_sortorder, table_heading_manufacturers, table_heading_price, table_heading_tax],
colModel:[
{name:'id',index:'id', width:(pageWidth*(5/100)), sortable:true, align:"center", search:true},
{name:'name',index:'name', width:(pageWidth*(20/100)), sortable:true, align:"left",true:false,resizable:true},
{name:'categories',index:'categories', width:(pageWidth*(10/100)), sortable:true, align:"left",resizable:true,search:true,stype:"select",searchoptions:{value:categories}},
{name:'model',index:'model', width:(pageWidth*(10/100)), sortable:false, align:"left",search:true,resizable:true,editable:true},
{name:'availability',index:'availability', width:(pageWidth*(10/100)), sortable:true, align:"left",resizable:true,search:true,stype:"select",searchoptions:{value:availability},editable:true,edittype:"select",editoptions:{value:availability}},
{name:'weight',index:'weight', width:(pageWidth*(5/100)), sortable:true, align:"center",search:false,editable:true},
{name:'quantity',index:'quantity', width:(pageWidth*(5/100)), sortable:true, align:"center",search:false,editable:true},
{name:'sortorder',index:'sortorder', width:(pageWidth*(5/100)), sortable:true, align:"center",search:false,editable:true},
{name:'manufacturers',index:'manufacturers', width:(pageWidth*(10/100)), sortable:true, align:"left",resizable:true,search:true,stype:"select",searchoptions:{value:manufacturers},editable:true,edittype:"select",editoptions:{value:manufacturers}},
{name:'price',index:'price', width:(pageWidth*(10/100)), sortable:false, align:"center",search:false},
{name:'tax',index:'tax', width:(pageWidth*(10/100)), sortable:true, align:"center",resizable:true,search:true,stype:"select",searchoptions:{value:taxes},editable:true,edittype:"select",editoptions:{value:taxes}}
],
rowNum:50,
rowList:[10,20,30,50,100],
Run Code Online (Sandbox Code Playgroud)
看看这段代码:
var pageWidth = $("#updatesList").parent().width() - 100;
Run Code Online (Sandbox Code Playgroud)
而这段代码:
{name:'id',index:'id', width:(pageWidth*(5/100)), sortable:true, align:"center", search:true},
{name:'name',index:'name', width:(pageWidth*(20/100)),
Run Code Online (Sandbox Code Playgroud)
数据表3.5+支持此通道
jQuery("#dt").jqGrid({
autowidth: true,
shrinkToFit: true
});
Run Code Online (Sandbox Code Playgroud)