ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: queensgambit9 on November 07, 2017, 02:49:07 pm

Title: Refresh data
Post by: queensgambit9 on November 07, 2017, 02:49:07 pm
I use data stored as JSON (array of objects) which is loaded through script src. I would like to refresh data (reload src) and update grid with new data ...what would be the best approach for this?
Title: Re: Refresh data
Post by: paramvir on November 07, 2017, 03:02:18 pm
Call refreshDataAndView() method to refresh data in grid.

Please also read this topic: https://paramquery.com/pro/tutorial#topic-loaddata
Title: Re: Refresh data
Post by: queensgambit9 on November 07, 2017, 06:39:49 pm
Trying:

Code: [Select]
      $.getScript(url)
    .done(function() {
$( "grid" ).pqGrid( "option", "dataModel.data", data);
$( "grid" ).pqGrid( "refreshDataAndView" );
    });

data is fetched but there seem to be no update...?
Title: Re: Refresh data
Post by: paramvir on November 07, 2017, 11:12:03 pm
data is undefined in your code.
Title: Re: Refresh data
Post by: queensgambit9 on November 08, 2017, 12:41:59 am
url is js src which contains
Code: [Select]
var data = [{col1:'value1' etc...}]
I get no erros when running, but data is not updated.
Title: Re: Refresh data
Post by: paramvir on November 08, 2017, 09:48:00 am
Are using the same variable data to send data to remote server and assigning the same data to grid? This is incorrect.

Please check the documentation of getscript for correct usage: https://api.jquery.com/jquery.getscript/
Title: Re: Refresh data
Post by: queensgambit9 on November 08, 2017, 01:08:23 pm
No, I just want to update grid with new data by loading the .js again, Like this:

var data = [{*updated data*...}]
$( "grid" ).pqGrid( "option", "dataModel.data", data);
$( "grid" ).pqGrid( "refreshDataAndView" );

Or how should I do this?
Thanks.


Title: Re: Refresh data
Post by: paramvir on November 08, 2017, 01:12:57 pm
yes the data should be updated data, which is not the case in your previously posted code.

You are not receiving any date from done callback.

In your code it's

Code: [Select]
.done(function()

It should be

Code: [Select]
.done(function( data )
Title: Re: Refresh data
Post by: queensgambit9 on November 08, 2017, 01:19:37 pm
Thanks, however still confused, why does this not work?

Code: [Select]
{
      type: 'button',
      label: "test",
      listener: function() {
  var data=[{col1:'value1'}]       
$( "grid" ).pqGrid( "option", "dataModel.data", data);
$( "grid" ).pqGrid( "refreshDataAndView" );
   
}}

Title: Re: Refresh data
Post by: paramvir on November 08, 2017, 09:34:17 pm
$( "grid" ) doesn't look right.

Please check the selector of your grid or better use "this" variable inside listener as reference to grid.

https://paramquery.com/pro/tutorial#topic-methods
Title: Re: Refresh data
Post by: queensgambit9 on November 09, 2017, 01:34:05 am
Thanks, solved.