Author Topic: Refresh data  (Read 7284 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Refresh data
« 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?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Refresh data
« Reply #1 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

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Refresh data
« Reply #2 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...?
« Last Edit: November 07, 2017, 08:29:36 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Refresh data
« Reply #3 on: November 07, 2017, 11:12:03 pm »
data is undefined in your code.

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Refresh data
« Reply #4 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.
« Last Edit: November 08, 2017, 01:52:36 am by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Refresh data
« Reply #5 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/

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Refresh data
« Reply #6 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.



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Refresh data
« Reply #7 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 )

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Refresh data
« Reply #8 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" );
   
}}


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6265
    • View Profile
Re: Refresh data
« Reply #9 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

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Refresh data
« Reply #10 on: November 09, 2017, 01:34:05 am »
Thanks, solved.