码迷,mamicode.com
首页 > 其他好文 > 详细

easyui datagird 列宽自适应

时间:2014-07-22 22:54:55      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   数据   width   io   

代码如下:

 1 onLoadSuccess: function (data) {
 2                 var rows = data.rows; //得到行数据  
 3                 var columnMaxCharacter = new Array(); //该列最大字符数  
 4                 //遍历所有行数据,获得该列数据的最大字符数  
 5                 var propertys = Object.getOwnPropertyNames(rows[0]);
 6                 for (var i = 0; i < rows.length; i++) {
 7                     for (var j = 0; j < propertys.length; j++) {
 8                         var s = eval(‘rows[‘ + i + ‘].‘ + propertys[j]);
 9                         //s = s.replace(‘<center>‘, ‘‘); //屏蔽html标签  
10                         //s = s.replace(‘</center>‘, ‘‘);
11                         if ((typeof columnMaxCharacter[propertys[j]]) == ‘undefined‘) {
12                             columnMaxCharacter[propertys[j]] = 0;
13                         }
14                         if ( s != null) {
15                             if (s.length > columnMaxCharacter[propertys[j]]) {
16                                 columnMaxCharacter[propertys[j]] = s.length;
17                             }
18                         }
19                     }
20                 }
21 
22                 //设置列宽度和字体  
23                 for (var j = 0; j < rows.length; j++) {
24                     //得到该列的字体  
25                     //    alert($("td[field=‘"+cls[j]+"‘] div").get(0).currentStyle);  
26                     // var fontSize=$("td[field=‘"+cls[j]+"‘] div").get(0).currentStyle.fontSize;//获得字体大小  
27                     //  fontSize= fontSize.replace("px","");//去掉px方便运算  
28                     var fontSize = 12;
29                     var w = fontSize * (columnMaxCharacter[propertys[j]] + 1); //求出宽度  
30                     //设定该列的宽度  
31                     $("td[field=‘" + propertys[j] + "‘] div").width(w);
32                 }
33 
34             }

easyui datagird 列宽自适应,布布扣,bubuko.com

easyui datagird 列宽自适应

标签:style   blog   color   数据   width   io   

原文地址:http://www.cnblogs.com/pyrebot/p/3849019.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!