• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

凉梁凉糕

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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

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

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

function queryTable(params) {
        $('#tt').datagrid({
            width: $(".queryTable").width()+60,
            height:($(window).height()-240),
            queryParams: params||{},
            pageNumber:parseInt(prepage)||'',
            pageSize:parseInt(prerows)||'',
            singleSelect: true,
            loadMsg: "Loading, please wait ...",
            pageList: [15,25,35,45,65,100],
            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!=0&&val==''){
                        rtn='';
                    }else{
                        switch(val){
                            case 1:
                                rtn='Official';
                                break;
                            case 2:
                                rtn='Skill';
                                break;
                            case 3:
                                rtn='Problem';
                                break;
                            case 4:
                                rtn='Entertainment';
                                break;
                            case 9:
                                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==1){
                        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==1){
//            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内部有不能识别的数据)

a - field单词拼写错误

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

 

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

posted on 2018-01-04 15:49  凉梁凉糕  阅读(1067)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3