问题描述:
easyui-datagrid 数据过多,序号显示不全
解决方案:
添加自适应
/**
* Datagrid中行数自适应长度显示
*/
$.extend($.fn.datagrid.methods, {
fixRownumber : function (jq) {
return jq.each(function () {
var panel = $(this).datagrid("getPanel");
var clone = $(".datagrid-cell-rownumber", panel).last().clone();
clone.css({
"position" : "absolute",
left : -1000
}).appendTo("body");
var width = clone.width("auto").width();
if (width > 25) {
$(".datagrid-header-rownumber,.datagrid-cell-rownumber", panel).width(width + 5);
$(this).datagrid("resize");
clone.remove();
clone = null;
} else {
$(".datagrid-header-rownumber,.datagrid-cell-rownumber", panel).removeAttr("style");
}
});
}
});
添加后调用方法fixRownumber即可
onLoadSuccess:function(data){
// datagrid_onLoadSuccess(data);
$(this).datagrid("fixRownumber");
}
添加后可能出现序号被放大,缩小后表格不能回到原始状态
可以修改css部分的最小宽度
.datagrid-cell-rownumber {
width: 30px;
text-align: center;
margin: 0;
padding: 0;
min-width: 26px;//就是这个位置
}
目的是让自适应可以一直计算
onLoadSuccess:function(data){
if(typeof(datagrid_onLoadSuccess) == 'function'){
datagrid_onLoadSuccess(data);
}
$(this).datagrid("fixRownumber");
}
如果想要更改项目中全部项目Jqurey.easyui.min.js中添加即可