Author Topic: Uncaught TypeError: Cannot read property 'pq_detail' of undefined  (Read 28603 times)

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
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!

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #1 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

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6320
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #2 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?

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #3 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

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6320
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #4 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 };
  }

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #5 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#

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,

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6320
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #6 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.

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #7 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

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #8 on: March 11, 2014, 05:39:21 pm »
In attachment you may see the code:

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6320
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #9 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



nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #10 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.
« Last Edit: March 11, 2014, 11:51:52 pm by nuno.nogueira »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6320
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #11 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

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #12 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!

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #13 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'.


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6320
    • View Profile
Re: Uncaught TypeError: Cannot read property 'pq_detail' of undefined
« Reply #14 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.