求大神:版本1.2 jquery-easyUI datagrid 列宽 自适宜问题

rwpeng86 2011-01-01 12:44:52
拜求大神:

需求:
1、必须在1.2版本下
2、浏览器大小变化时,test表 边框已调好,如何调整每个列宽 自适应表格宽度(不刷新reload情况下,就是不知如何获取每个列宽)


不知如何获取 datagrid 列宽


页面源码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery EasyUI</title>
<link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../themes/icon.css">
<script type="text/javascript" src="../jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../jquery.easyui.min.js"></script>
<script>
$(function(){
var width2 = window.innerWidth*0.97;
var bodyWidth = document.body.clientWidth;
//alert(bodyWidth);
$('#test').datagrid({
title:'My Title',
iconCls:'icon-save',
nowrap: false,
striped: true,
collapsible:true,
url:'datagrid_data.json',
sortName: 'code',
sortOrder: 'desc',
remoteSort: false,
idField:'code',
frozenColumns:[[
{field:'ck',checkbox:true},
{title:'code',field:'code',sortable:true}
]],
columns:[[
{title:'Base Information',colspan:3},
{field:'opt',title:'Operation',width:(width2-95)*0.20,align:'center', rowspan:2,
formatter:function(value,rec){
return '<span style="color:red" width='+(width2-95)*0.20+'>Edit Delete</span>';
}
}
],[
{field:'name',title:'Name',width:(width2-95)*0.25},
{field:'addr',title:'Address',width:(width2-95)*0.25,rowspan:2,sortable:true,
sorter:function(a,b){
return (a>b?1:-1);
}
},
{field:'col4',title:'Col41',width:(width2-95)*0.25,rowspan:2}
]],
pagination:true,
rownumbers:true,
toolbar:[{
id:'btnadd',
text:'Add',
searchItems:[{id:"searchAutName",//文本框的id
text:'权限名称',//文本标签
field:'authName',//文本框的name
size:10//文本框的长度
},{id:"searchAutName",//文本框的id
text:'权限名称',//文本标签
field:'authName',//文本框的name
size:10//文本框的长度
},{id:"searchAutName",//文本框的id
text:'权限名称',//文本标签
field:'authName',//文本框的name
size:10//文本框的长度
}],//自己手动添加的搜索文本框
iconCls:'icon-add',
handler:function(){
$('#btnsave').linkbutton('enable');
alert('add')
}
},{
id:'btncut',
text:'Cut',
iconCls:'icon-cut',
handler:function(){
$('#btnsave').linkbutton('enable');
alert('cut')
}
},'-',{
id:'btnsave',
text:'Save',
disabled:true,
iconCls:'icon-save',
handler:function(){
$('#btnsave').linkbutton('disable');
alert('save')
}
}]
});
var p = $('#test').datagrid('getPager');
if (p){
$(p).pagination({
onBeforeRefresh:function(){
alert('before refresh');
}
});
}
});





<!-- 浏览器窗口 变化时触发函数 -->
$(window).resize(function(){
resize();
});
function resize(){
//alert(window.innerWidth*0.98);
$('#test').datagrid('resize', {
width:window.innerWidth*0.97
});
alert($("#tt").attr("columns"));
//alert($('#addr').html());
//alert($('#addr').html());
//$("th:parent").each(function(i) {
//this.style.backgroundColor = '#dddddd';
//alert(this.width);

//this.style.width = window.innerWidth*0.97*0.16
//this.field="dddd"
//$(this).attr("field","ccc");
//});
//$("th:parent").css("width","20px");
}
function getSelected(){
var selected = $('#test').datagrid('getSelected');
if (selected){
alert(selected.code+":"+selected.name+":"+selected.addr+":"+selected.col4);
}
}
function getSelections(){
var ids = [];
var rows = $('#test').datagrid('getSelections');
for(var i=0;i<rows.length;i++){
ids.push(rows[i].code);
}
alert(ids.join(':'));
}
function clearSelections(){
$('#test').datagrid('clearSelections');
}
function selectRow(){
$('#test').datagrid('selectRow',2);
}
function selectRecord(){
$('#test').datagrid('selectRecord','002');
}
function unselectRow(){
$('#test').datagrid('unselectRow',2);
}
function mergeCells(){
$('#test').datagrid('mergeCells',{
index:2,
field:'addr',
rowspan:2,
colspan:2
});
}
</script>
</head>
<body>
<h1>DataGrid</h1>
<div style="margin-bottom:10px;">
<a href="#" onclick="resize()">resize</a>
<a href="#" onclick="getSelected()">getSelected</a>
<a href="#" onclick="getSelections()">getSelections</a>
<a href="#" onclick="clearSelections()">clearSelections</a>
<a href="#" onclick="selectRow()">selectRow</a>
<a href="#" onclick="selectRecord()">selectRecord</a>
<a href="#" onclick="unselectRow()">unselectRow</a>
<a href="#" onclick="mergeCells()">mergeCells</a>
</div>

<table id="test"></table>
<div id="xx" style="background-color :#00FF00;width:95px"> 95px</div>


</body>
</html>
...全文
650 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rwpeng86 2011-01-06
  • 打赏
  • 举报
回复
谢了 虽然不是我要的答案
逍遥庄主 2011-01-01
  • 打赏
  • 举报
回复
你试着把这个table 放在一个easyui-layout 的region里在试试 写上fit="true"

87,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧