EasyUI Forum

General Category => General Discussion => Topic started by: Alfred on October 21, 2019, 07:57:08 PM



Title: TypeError: $.data(...) is undefined
Post by: Alfred on October 21, 2019, 07:57:08 PM
Whenever I call a function to open a dialog which has a datagrid, I got the following error in the console.

Code:
TypeError: $.data(...) is undefined

However this error does not cause any misbehaviour in my application. My code goes like this:

Code:
function openDialog(){
    $('body').desktop('openApp', {
         href:'datagridview.php',  
         //other code
    });
}

datagridview.php

Code:
<body>
    <table id="dg" data-options="href:view.php" class="easyui-datagrid">
         <th field="categoryName" halign="center" width="20" sortable="true" align="left">Category</th>
          //other codes follow
    </table>
</body>

I tested the code in Firefox, Chrome, Internet Explorer 11. I do not see any misbehavior. But since It is an error, I want to get rid of it. Please help.

Thanks
Alfred


Title: Re: TypeError: $.data(...) is undefined
Post by: stworthy on October 23, 2019, 07:57:09 PM
Your 'datagridview.php' should be:
Code:
<table id="dg" data-options="fit:true" class="easyui-datagrid">
<thead>
<tr>
<th field="categoryName" halign="center" width="200" sortable="true" align="left">Category</th>
<th field="categoryName2" halign="center" width="200" sortable="true" align="left">Category2</th>
</tr>
</thead>
</table>

No error occurs on the console.


Title: Re: TypeError: $.data(...) is undefined
Post by: Alfred on October 27, 2019, 09:44:29 PM
Thanks for the reply.

the datagridview.php contains a a datagrid definion. It has a different url for getting the datagrid json. So the complete code looks like below:

This code is in index.php:

Code:
function openDialog(){
    $('body').desktop('openApp', {
         href:'datagridview.php',  
         //other code
    });
}

We have another file datagridview.php, which has the following datagrid code:

Code:
<table id="dg" data-options="url:view.php" class="easyui-datagrid">
         <th field="categoryName" halign="center" width="20" sortable="true" align="left">Category</th>
          //other codes follow
</table>

So when we run
Code:
openDiaglog()
function, It opens a new dialog. Inside the dialog, we have a datagrid that will load json from view.php. So the error still exists. The complete console error is:

TypeError: $.data(...) is undefined easyui.min.js:1:245666
    getPager http://test.com/js/easyui.min.js:1
    datagrid http://test.com/js/easyui.min.js:1
    loaded http://test.com/js/easyui.min.js:1
    jQuery 2
    loaded http://test.com/js/easyui.min.js:1
    datagrid http://test.com/js/easyui.min.js:1
    _78f http://test.com/js/easyui.min.js:1
    success http://test.com/js/easyui.min.js:6
    jQuery 4

I hope you can fix the error.

Thanks and regards,
Alfred





Title: Re: TypeError: $.data(...) is undefined
Post by: stworthy on October 28, 2019, 02:33:58 AM
Please look at this example https://www.jeasyui.com/demo/test/test8.html. It works fine.

test8_1.php
Code:
<table id="dg" data-options="fit:true,url:'test8_2.php'" class="easyui-datagrid">
<thead>
<tr>
<th field="categoryName" halign="center" width="200" sortable="true" align="left">Category</th>
<th field="categoryName2" halign="center" width="200" sortable="true" align="left">Category2</th>
</tr>
</thead>
</table>

test8_2.php
Code:
<?php

$data 
= array(
array('categoryName'=>'categoryName11','categoryName2'=>'categoryName12'),
array('categoryName'=>'categoryName21','categoryName2'=>'categoryName22'),
array('categoryName'=>'categoryName31','categoryName2'=>'categoryName32'),
);

echo 
json_encode($data);


Title: Re: TypeError: $.data(...) is undefined
Post by: Alfred on October 28, 2019, 07:52:35 PM
Thanks for the reply.

Your example just works fine, yet the error still exists in my attempted code. It may be due to the way the pagination works. In your example the pagination is not included. I am using jquery 1.12.4. and easyui 1.7.x.