EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Alfred on April 30, 2019, 05:54:52 AM



Title: How to remove the following error
Post by: Alfred on April 30, 2019, 05:54:52 AM
Though this error does not cause any unexpected behavior or change in my application, it always appear on the console. So I am looking for ways to remove the error, but could not find the solution.

Code:
Uncaught TypeError: Cannot read property 'panel' of undefined
    at Object.getPager (easyui.min.js:1)
    at n.fn.init.$.fn.datagrid (easyui.min.js:1)
    at HTMLTableElement.<anonymous> (easyui.min.js:1)
    at Function.each (jquery.min.js:2)
    at n.fn.init.each (jquery.min.js:2)
    at Object.loaded (easyui.min.js:1)
    at n.fn.init.$.fn.datagrid (easyui.min.js:1)
    at easyui.min.js:1
    at Object.success (easyui.min.js:1)
    at i (jquery.min.js:2)

I hope you can solve the problem.

Thanks and regards,

Alfred


Title: Re: How to remove the following error
Post by: jarry on May 02, 2019, 12:36:00 AM
When calling the 'getPager' method before creating the datagrid, the error occurs. Please make sure to initialize the datagrid component before calling this method.


Title: Re: How to remove the following error
Post by: Alfred on May 11, 2019, 07:44:25 PM
Please show an example.


Thanks
Alfred


Title: Re: How to remove the following error
Post by: jarry on May 13, 2019, 07:11:50 AM
Look at this example:
Code:
<table id="dg" class="easyui-datagrid" data-options="pagination:true" title="Custom DataGrid Pager"></table>
<script type="text/javascript">
var pager = $('#dg').datagrid('getPager');
console.log(pager)
</script>

The 'getPager' method is called when the page is loaded. It will raise errors because it is called before creating the datagrid. To solve this issue, use this code instead.
Code:
<table id="dg" class="easyui-datagrid" data-options="pagination:true" title="Custom DataGrid Pager"></table>
<script type="text/javascript">
$(function(){
var pager = $('#dg').datagrid('getPager');
console.log(pager)
})
</script>


Title: Re: How to remove the following error
Post by: Alfred on May 13, 2019, 07:22:55 AM
Thanks for the reply. How do I do it in the combogrid? This is the one that causes the error.

Code:
<input name="feeinfo" id="ipBox" class="easyui-combogrid"
  data-options="panelWidth:800, mode:'remote', method:'get', pagination:true,
  idField:'id', textField:'name',  hasDownArrow:true, striped:true,
  prompt:'Type to search..',  url:'Data/list',
  columns: [[
    {field:'id',title:'<b>Id</b>', halign:'center', align:'center', width:40,sortable:true},
    {field:'name',title:'<b>Name</b>', halign:'center', align:'left', width:120,sortable:true},
  ]], fitColumns: true, panelHeight:250,
  onSelect:function(index, row) {
      showInfo(row.id);
      $('#ipBox').combogrid('clear');
  },
  panelEvents: $.extend({}, $.fn.combogrid.defaults.panelEvents, {
      mousedown: function(){}
  }),
  onHidePanel:function(index,row){
      $(this).combogrid('close');
      $('#ipBox').combogrid('clear');
  }, emptyMsg:'<span style=color:red>No Data...</span>'" style="width:100%; height:35px;">

I did try with the following but it does not work:

Code:
$(function(){
    $('#ipBox').combogrid({
        onBeforeLoad: function(param){
           var g = $('#ipBox').combogrid('grid');
           var pager = g.datagrid('getPager');
        }
      });
   });


Title: Re: How to remove the following error
Post by: jarry on May 13, 2019, 06:53:07 PM
This example is created from your code. No error occurs.
http://code.reloado.com/oluruy/edit#preview


Title: Re: How to remove the following error
Post by: Alfred on May 13, 2019, 07:29:27 PM
Thanks Jarry. But my combogrid is inside a dialog. The problem is still there.


Title: Re: How to remove the following error
Post by: jarry on May 15, 2019, 06:46:05 PM
You should put all the script code into the <body> to be loaded from the dialog.