方法一:容易,实用的方法

在jquery.easyui.min.js中查找到field.replace(/[\.|\s]/g, "-")在其后添加replace

例子:field.replace(/[\.|\s]/g, "-").replace(/./g, function ($1) { return $1.charCodeAt(0).toString(16); });//有改动,目的是将其转为十六进制

方法二:用过,借鉴的方法:onLoadSuccess:直接设置列宽

$('#stthb_div').datagrid({
data: [],
//title: "分析",
//iconCls:'icon-save',
padding: "30px",
nowrap: false,
singleSelect: true,
//striped: true,
height: win_h,
collapsible: true,
resizable: false,
//sortable: true,
remoteSort: false,//本地数据排序
//frozenColumns//不会滚动
columns: [
columns
]
//bind数据成功设置列宽度
, onLoadSuccess: function (data) {
//datagrid头部 table 的最后一个tr 的td们,即columns的集合
var headerTds = $(".datagrid-header-inner table tr:last-child").children();
//datagrid主体 table 的首个tr 的td们,即第一个数据行
var bodyTds = $(".datagrid-body table tr:first-child").children();
var totalWidth = 0; //合计宽度,用来为datagrid头部和主体设置宽度
//循环设置宽度
bodyTds.each(function (i, obj) {
var headerTd = $(headerTds.get(i));
var bodyTd = $(bodyTds.get(i));
//$("div:first-child", headerTds.get(i)).css("text-align", "center");
var headerTdWidth = headerTd.width(); //获取第i个头部td的宽度
//这里加5个像素 是因为数据主体我们取的是第一行数据,不能确保第一行数据宽度最宽,预留5个像素。有兴趣的朋友可以先判断最大的td宽度都在进行设置
var bodyTdWidth = bodyTd.width();
var width = 0;
//如果头部列名宽度比主体数据宽度宽,则它们的宽度都设为头部的宽度。反之亦然
if (headerTdWidth > bodyTdWidth) {
width = headerTdWidth;
bodyTd.width(width);
headerTd.width(width);
totalWidth += width;
} else {
width = bodyTdWidth;
headerTd.width(width);
bodyTd.width(width);
totalWidth += width;
}
});
var bodyTable = $(".datagrid-body table:first-child");
//循环完毕即能得到总得宽度设置到头部table和数据主体table中
//bodyTable.width(totalWidth + 55);
bodyTable.width($(".datagrid-header-inner table tr:last-child").width());
///将所有的列都设置为可以排序
var columns = $("#stthb_div").datagrid("options").columns[0];
for (i = 0; i < columns.length; i++) {
columns[i].sortable = true;
};
}
});

最新文章

  1. 【笔记】js Function类型 内部方法callee
  2. python unicode转中文及转换默认编码
  3. NOIP 考前 高斯消元练习
  4. Android--多线程之Handler(转)
  5. iBatis.Net(C#)系列Demo源码
  6. Android-自定义meta-data扩展数据
  7. Java Hour 25 Packages
  8. nrf51822-广播模式
  9. 内存泄露(OOM)现象及举例
  10. jQuery Ajax 实例 ($.ajax、$.post、$.get)【转载】
  11. inconvertible types; cannot cast &#39;android.supoort.v4.app.Fragment&#39; to &#39;com.example.sevenun.littledemo.fragment.NewsTitleFragment&#39;
  12. LeetCode_Distinct Subsequences
  13. 柯南君:看大数据时代下的IT架构(7)消息队列之RabbitMQ--案例(routing 起航)
  14. openSUSE13.2安装Nodejs并更新到最新版
  15. linux $ 类型变量 及Makefile 中 $ 类型变量的含义
  16. openstack添加数据库
  17. kv_storage.go
  18. 7.7 wordcnt.c 程序
  19. [转]PhpStorm快捷键大全
  20. 微信小程序 thirdScriptError sdk uncaught third Error regeneratorRuntime is not defined ReferenceError: regeneratorRuntime is not defined

热门文章

  1. Git介绍下载安装以及基本使用
  2. 22 备份整合方案应用:Proxmox BS
  3. 18 网路进阶设定:Bridge、LACP、VLAN
  4. centos7 开机自启动脚本
  5. Python 常用小例子
  6. SVN的安装和使用手册2
  7. 【面试题】ES6语法五之箭头函数
  8. 1163:阿克曼(Ackmann)函数
  9. CloudFlare Workers部署Pixiv图片反代
  10. [BOM] 封装一下cookie