easyui datagrid 表头与数据错位
方法一:容易,實用的方法
在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;
};
}
});
?
轉載于:https://www.cnblogs.com/wusm/p/5643906.html
總結
以上是生活随笔為你收集整理的easyui datagrid 表头与数据错位的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP读取数据库表显示到前台
- 下一篇: RGB颜色二值化