ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: stoodin on June 20, 2014, 08:33:43 pm

Title: datamodel.data is not ready on the load event
Post by: stoodin on June 20, 2014, 08:33:43 pm
Hi,
I am doing some logic in the grid load event and I need all data to be populated and ready by this time. I am loading the date from JSON.
I see very incosistent behaviour. Sometimes the data is ready sometimes is not and the data coming always the same from the same source. Here is my code.

    $grid.on( "pqgridload", function( event, ui ) {
       if (ui.dataModel.data && ui.dataModel.data.length > 0) {
             .... do some logic
      }
}
Title: Re: datamodel.data is not ready on the load event
Post by: paramvir on June 20, 2014, 10:26:55 pm
Could you please send a test case whereby the mentioned inconsistent behavior of load event can be reproduced.
Title: Re: datamodel.data is not ready on the load event
Post by: stoodin on June 20, 2014, 10:54:13 pm
It won't be possible. The data is loaded by ajax from the server.
I think if the server has delay in the reply then the data is not getting populated.
I am thinking to put an infinite loop until the datamodel populated.
something like
while (ui.dataModel.data.length <= );


Any other ideas?
Title: Re: datamodel.data is not ready on the load event
Post by: paramvir on June 22, 2014, 07:27:46 pm
load event is either fired or not depending upon availability of remote data so infinite loop won't do.

It looks like timout, use dataModel.error to ensure that it's a timeout error.

Find the reason why server script is slow and try to fix it.

you can also try increase the timeout value of ajax request and server script.
Title: Re: datamodel.data is not ready on the load event
Post by: stoodin on June 24, 2014, 03:00:56 am
I am using your built in dataModel to call ajax (see bellow). Is there a way to handle the exception like regular ajax call?
        dataModel:{
            location: "remote",
            recIndx: "recId",
            sorting: "local",
            dataType: "JSON",
            method: "GET",
            url: "getTcTrans.do",
            getData: function (dataJSON) {
               return {data: dataJSON};
            }
        },
Title: Re: datamodel.data is not ready on the load event
Post by: paramvir on June 24, 2014, 09:37:56 am
It's mapped to jQuery ajax internally.

dataModel.error callback can be used to find the reason of ajax error.

http://paramquery.com/pro/api#option-dataModel-error
Title: Re: datamodel.data is not ready on the load event
Post by: stoodin on June 24, 2014, 06:34:34 pm
Implemented but there are no errors.

I think my problem is different that I originally thought.
I have 3 grids on one page and I try to do some calculation based on all 3 grids data in one of the grids load method.
My assumption was if the grid is the last in order on the page all other grids should be done with loading data, however sometime it is not the case.

Question:
How do I make sure that all 3 my grids finished loading data?

Thanks a lot for your help.
Title: Re: datamodel.data is not ready on the load event
Post by: paramvir on June 24, 2014, 07:48:51 pm
You may use global ajaxComplete callback

http://api.jquery.com/ajaxcomplete/
Title: Re: datamodel.data is not ready on the load event
Post by: stoodin on June 24, 2014, 08:21:16 pm
Excellent. That is exactly what I need.
Thanks a lot again, especially for the stuff that doesn't related to you grid directly!!!