easyui datagrid 遇到的坑 cannot read property ·· pageNum bug and so on

时间:2024-04-15 21:06:40

1 本人刚刚接到一个bug,就是初始化时若设置了datagrid到指定页数,点击下一页显示不对,4 --> ‘4’+1=41的字符串形式,再点击超出页码范围直接到最后一页;

原因:因为 pageNumber接收的是整数型的数据,而你遇到这种bug说明你传入的非整型的数据,需要利用parseInt进行转化一下,就不会再出现这样的错误了;

function queryTable(params) {
$('#tt').datagrid({
width: $(".queryTable").width()+,
height:($(window).height()-),
queryParams: params||{},
pageNumber:parseInt(prepage)||'',
pageSize:parseInt(prerows)||''
,
singleSelect: true,
loadMsg: "Loading, please wait ...",
pageList: [,,,,,],
idField:'id',
url:'/CarlcareManager/posts/findPostLists',
method:'get',
columns:[[
{field:'post_language',title:'Language',width:'8%',align:'center'},
{field:'post_type',title:'Type',align:'center',width:'8%',formatter:function(val,obj,idx){
var rtn='';
if(val!=&&val==''){
rtn='';
}else{
switch(val){
case :
rtn='Official';
break;
case :
rtn='Skill';
break;
case :
rtn='Problem';
break;
case :
rtn='Entertainment';
break;
case :
rtn='Others';
break;
}
}
return rtn;
}},
{field:'publish_time',title:'Publishing time',width:'8%',align:'center',formatter:function(val,obj,idx){
return dateFormat(parseInt(val));
}},
{field:'username',title:'Owner',width:'8%',align:'center'},
{field:'post_title',title:'Title',width:'18%',align:'center'},
{field:'view_count',title:'Views',width:'6%',align:'center'},
{field:'reply_count',title:'Comments',width:'6%',align:'center'},
{field:'collect_count',title:'Favorites',width:'6%',align:'center',width:'10%'},
{field:'comment',title:'Marks',width:'10%',align:'center'},
{field:'post_status',title:'Status',width:'6%',align:'center',formatter:function(val,obj,idx){
var rtn='';
if(val==){
rtn='Published';
}else{
rtn='Delete';
}
return rtn;
}},
{field:'view_status',title:'Operation',width:'10%',align:'center',formatter:function(value,obj,index){
var html='';
if(value==){
// html="<a class='viewed' type='button' name='replyStatus' onclick='postDetail(obj.id,obj.post_status)' href='../customer/postDetailPage?postId="+obj.id+"&postStatus="+obj.post_status+"' value='View'>View</a>";
html="<a class='alink viewed' type='button' name='replyStatus' onclick='postDetail("+obj.id+","+obj.post_status+")' value='View'>View</a>"; }else{
// html="<a class='unviewed' type='button' name='replyStatus' onclick='postDetail(obj.id,obj.post_status)' href='../customer/postDetailPage?postId="+obj.id+"&postStatus="+obj.post_status+"' value='UnView'>UnView</a>";
html="<a class='alink unviewed' type='button' name='replyStatus' onclick='postDetail("+obj.id+","+obj.post_status+")' value='UnView'>UnView</a>"; }
return html;
}} ]],
onLoadSuccess:function(data){
},
onLoadError:function(){
}
});
$('#tt').datagrid("clearSelections");
}

2 datagrid表格初始化时总是会报错 cannot read property ‘width/height··’

easyui datagrid 遇到的坑 cannot read property ·· pageNum bug and so on

easyui datagrid 遇到的坑 cannot read property ·· pageNum bug and so on

我碰到的发生这种错误有两种原因(easyui datagrid内部有不能识别的数据)

a - field单词拼写错误

b - queryTable请求地址拿回来的数据格式不对,比如下面,拿回的数据若不是rows会报类似错误;

easyui datagrid 遇到的坑 cannot read property ·· pageNum bug and so on easyui datagrid 遇到的坑 cannot read property ·· pageNum bug and so on

3 今天在使用jquery easyui时遇到一个问题,easyui的datagrid无法加载。可能原因是field里面存在空格;