easyui datagrid(‘getPager’)为空问题 Cannot read property 'panel' of undefined

复制代码
<table id='grid' class='easyui-datagrid' style='width:100%;height:450px' 
            title='列表' iconCls='icon-table' pagination='true' rownumbers='true' fitColumns='true' singleSelect='true'  striped='true'  >  
        <thead>  
            <tr>  
                 
                <th field='id' width='10' hidden='true'>编号</th>      
                <th field='name' width='20'align='center'>姓名</th>   
 
                <th field='created_user_name' width='20' align='center'>创建人</th> 
                <th field='date_entered' width='40' align='center'>创建时间</th>  
                <th field='description' width='50' align='center'  hidden='true' >备注</th>  
            </tr>  
        </thead>  
</table> 
复制代码

使用下面语句发现竟然提示为空,然后看了下源码,竟然没有id="grid"元素,可是我明明给table定义了id="grid" class="easyui-datagrid"让easyui自动加载为datagrid,已是感觉可能是自动识别的问题,就把class="easyui-datagrid"给删了,然后在js里面定义。

var pg = $("#grid").datagrid("getPager");

解决方法:

加上这句: $( '#grid' ).datagrid();

复制代码
    //分页事件
    $( '#grid' ).datagrid();  //加这句即可
    var pg = $("#grid").datagrid("getPager");
    if(pg)
    {
      $(pg).pagination({
         onBeforeRefresh:function(){
            console.log('before refresh');
             },
              onRefresh:function(pageNumber,pageSize){
            console.log(pageNumber);
            console.log(pageSize);
              },
              onChangePageSize:function(){
            console.log('pagesize changed');
          },
          onSelectPage:function(pageNumber,pageSize){
              console.log(pageNumber);
              console.log(pageSize);
          }
      });
    }
复制代码

竟然神奇的可以了。感谢原文作者的分享。

原文链接:https://blog.csdn.net/u012925172/article/details/84749663

posted @   海乐学习  阅读(568)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2017-03-09 Python读文本文件中文乱问题
2017-03-09 Python读文本文件
2017-03-09 C# 获取文件名及扩展名
点击右上角即可分享
微信分享提示