ParamQuery grid support forum

General Category => Bug Report => Topic started by: nuno.nogueira on March 10, 2014, 05:51:10 pm

Title: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 10, 2014, 05:51:10 pm
I get the error:

Code: [Select]
Uncaught TypeError: Cannot read property 'pq_detail' of undefined
When refreshing the data in the table.

It happens when the table is empty: I have no idea why this error is now being displayed now but it seems the table isn't properly refreshed when the table is empty.

Thanks for helping!
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 10, 2014, 06:16:33 pm
I should add that when deleting the last row of the table I get:

Code: [Select]
Uncaught TypeError: Cannot read property '0' of undefined
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 10, 2014, 06:21:20 pm
Is it a master detail grid?

Quote
When refreshing the data in the table.

Which one? master or detail

Quote
when deleting the last row of the table I get:

master or detail?

could you include a little test case?
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 10, 2014, 06:29:55 pm
It is both (when deleting the last row of detail, you delete also the last row of the master).

In my application, I have new data per month (controlled with the links at the bottom "somar" and "subtrair".

When opening an empty month (for example Abril-2014) the table doesn't refresh and the error starts breaking the code.

Have a look at:

[url=http://www.portal-gestao.com/or
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 11, 2014, 11:12:48 am
Your url is broken.

Have you copied the code to expand first row from the demo. You should check the length of data before expanding the row.

Code: [Select]
  if (data && data.length) {
     data[0]['pq_detail'] = { 'show': true };
  }
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 11, 2014, 03:08:33 pm
Hi,

The link isn't broken, but this forum is cutting part of the text.
You may see the example here: http://www.portal-gestao.com/or%C3%A7amento.html# (http://www.portal-gestao.com/or%C3%A7amento.html#)

Go to an empty grid, clicking in "Somar" at the bottom and see the error.

I am not expading any rows.

This error is breaking the code,
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 11, 2014, 05:34:44 pm
I can see the error.

What does somar do. It looks like it refreshes the whole grid. What is the code of this function.
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 11, 2014, 05:37:10 pm
It adds a month and refreshes the grid with the data of that month.
Subtrair deducts a month.

Here's the function being called:
[code]function mudaMes(acrescenta) {
      var dataCorrente = new Date(hoje.getFullYear(), hoje.getMonth() + acrescenta, 1);
      $('#mescorrente').html("Este m
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 11, 2014, 05:39:21 pm
In attachment you may see the code:
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 11, 2014, 09:49:33 pm
your issue may be related to the wrong way you are refreshing the grid. You should not pass the whole constructor object while refreshing the grid.

Instead of that just pass the postData option and call refreshDataAndView


Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 11, 2014, 10:57:10 pm
It is related with the month change event, it seems.

I now get the error:
Code: [Select]
Uncaught TypeError: Cannot read property '3' of undefined
When changing the month to April.

This is the code I'm now using:
Code: [Select]
var obj = {
            dataModel: {
                postData: {
                    mesSelect: mes,
                    anoSelect: ano
                }
        };

        var $objOrcamento = $("#tabela").pqGrid(obj);
        $objOrcamento.pqGrid("refreshDataAndView");

}

Also  tried:
Code: [Select]
$.ajax($.extend({}, ajaxObj, {
            data: {
                mesSelect: mes,
                anoSelect: ano
            }
        }));

But it tells me that ajaxObj is not defined, although I moved it out of any functions.
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 12, 2014, 10:25:55 pm
I'm afraid to say it's still incorrect way to pass options to the grid.

Please go through the documentation on how to pass postData after initialization.

http://paramquery.com/pro/api#option-dataModel-postData
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 13, 2014, 12:36:58 am
I also tried:

Code: [Select]
$( "#tabela" ).pqGrid( "option", "dataModel.postData", {mesSelect:mes, anoSelect:ano});

Which returns exactly the same error:
Code: [Select]
Uncaught TypeError: Cannot read property '3' of undefined
Although the request is sent to the server and returns:
Code: [Select]
{"data":[]}
Because there is No data for this month (April), which is correct.

The error is thrown only when the table is empty!
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 14, 2014, 12:13:05 am
Hello,

Can you help with this? How am I supposed to refresh the table?

Code: [Select]
$( "#tabela" ).pqGrid( "option", "dataModel.postData", {mesSelect:mes, anoSelect:ano});
Which returns an empty data JSON file. OK.

And:

Code: [Select]
$("#tabela").pqGrid("refresh");
Or:
Code: [Select]
$("#tabela").pqGrid("refreshDataAndView");
That does not refresh the main grid and returns the mentioned error in the details'.

Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 14, 2014, 12:13:56 am
Could you use dev version of js and find out the line where exactly its throwing the error.
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 14, 2014, 12:21:14 am
Sure, it is on lines 653 and 136.

Note: You may see the error at: http://www.portal-gestao.com/or%C3%A7amento.html# (http://www.portal-gestao.com/or%C3%A7amento.html#)

If an empty month is loaded from scratch, no problem, the error is thrown only when changes are made to the data model.

Thanks for your support!
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 14, 2014, 12:29:05 am
your dev version is minified. It's difficult to see where is the issue. Could you use the dev file without any modification.

and which version are you using 2.0.3 or 2.0.4
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 14, 2014, 12:41:22 am
Pls see attached, this forum is a bit complicated...
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 17, 2014, 05:24:56 pm
Hi,

Did you have the chance to look into this?
Everything else seems to be working, except refreshing an empty table.

Thanks for your support!
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 17, 2014, 11:02:06 pm
The issue couldn't be reproduced at my end.

You have to include all js files in non minified format if you want me to take a look into what's going on.
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 18, 2014, 03:00:57 pm
Hi,

Here they are:
http://portal-gestao.com/budget/orcamento.js (http://portal-gestao.com/budget/orcamento.js)

You may see the page at:
http://www.portal-gestao.com/or%C3%A7amento.html (http://www.portal-gestao.com/or%C3%A7amento.html)

This is most likely a bug, so I'd like to have you looking into it.

Thanks!
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 18, 2014, 03:51:04 pm
The scripts included inside the page are still minified.

Please include non - minified scripts inside the page and kindly mention detailed steps to reproduce the issue/issues.
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 18, 2014, 05:03:03 pm
Hello,

We have disabled mod_pagespeed, I think the scripts are non-minified now.

In addition to the above scripts, the month-changer script should also be considered:
http://www.portal-gestao.com/budget/mescorrente.js (http://www.portal-gestao.com/budget/mescorrente.js)

To reproduce the error, simply go to:
http://www.portal-gestao.com/or%C3%A7amento.html

And click "somar" at the bottom to go to the following month (april)
You'll see that there's no data but the main grid will not update. If you try to expand the sub-grid, you'll get the error.

The desired result should be an empty table with the message "no rows..."

Thanks!
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 20, 2014, 03:40:52 pm
Hello,

Were you able to reproduce the error?
I'm on a bit of time pressure here to close this project, will it be possible to fix the problem?

If it is ok, I'll minify the files again. Please advise.

Thanks
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 20, 2014, 11:23:20 pm
Nuno

You would get the fix by Tuesday. It would be helpful ( just in case )  if you can keep the files unminified until this weekend.
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 21, 2014, 09:40:54 pm
Ok, thanks a lot, I'll leave the files unminified.
But, the link is now:

http://ebudget.portal-gestao.com/app (http://ebudget.portal-gestao.com/app)

Basically, the same stuff..
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: paramvir on March 25, 2014, 03:58:44 pm
Nuno

As a workaround, please modify your getData method.

Code: [Select]
getData: function (dataJSON) {
        var data = dataJSON.data;
         if(!data || !data.length){
              var that=$(this).pqGrid("getThis").that;
              that.dataGM=null;
         }

         return {
              curPage: dataJSON.curPage,
              totalRecords: dataJSON.totalRecords,
              data: data
         };
 }
Title: Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
Post by: nuno.nogueira on March 25, 2014, 11:43:42 pm
Hi,

That has fixed it, thanks!

 :D