pyrebot

Better not to ignore the past but learn from it instead. Otherwise, history has a way of repeating itself.

博客园 首页 新随笔 联系 订阅 管理

代码如下:

 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             }
posted on 2014-07-16 16:37  pyrebot  阅读(336)  评论(0编辑  收藏  举报