Author Topic: Second grid binding  (Read 2337 times)

flipo

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 5
    • View Profile
Second grid binding
« on: March 03, 2018, 09:21:09 pm »
I have 2 grids with remote data and infinity scrolling on the same page in a different div.
When a row is selected in the first grid, the second grid shows the result with the code

Code: [Select]
$('#grid2').pqGrid('option','dataModel.data',[]);
$('#grid2').pqGrid('refresh');
$('#grid2').pqGrid('option','dataModel.url','<?= $grid2_url ?>&id='+id&pq_start=0&pq_curpage=1&pq_rpp=50&);
$('#grid2').pqGrid('refreshDataAndView');

But the grid shows all previous rows for the rows greater that the new total.
Is there a better and correct way for binding 2 grids?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: Second grid binding
« Reply #1 on: March 05, 2018, 10:12:59 am »
pqIS2.init() needs to be called to clear the cache of 2nd grid before requesting new data.

Code: [Select]
pqIS2.init()
$('#grid2').pqGrid('option','dataModel.url','<?= $grid2_url ?>&id='+id&pq_start=0&pq_curpage=1&pq_rpp=50&);
$('#grid2').pqGrid('refreshDataAndView');

flipo

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Second grid binding
« Reply #2 on: March 05, 2018, 08:05:25 pm »
Thanks, but how can I acces pqIS2.init() from a script outside the first script?
Now I have the error message 'Uncaught ReferenceError: pqIS2 is not defined'.
Using goldenlayout as div for the tables, scripts are loading while constructing the page.
For the first grid I have an event to load the second grid:
Code: [Select]
var obj = {...
  rowSelect:function(evt,ui){
   var row=ui.addList[0];
   var id=row.rowData.id;

   pqIS2.init()
$('#grid2').pqGrid('option','dataModel.url','<?= $grid2_url ?>&id='+id&pq_start=0&pq_curpage=1&pq_rpp=50&);
$('#grid2').pqGrid('refreshDataAndView');
   }
}
But the original pqIS2.init() is in another script for constructing the second div and not in the same script.
So how can I redefine it or acces it?


[size=78%] [/size]

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6298
    • View Profile
Re: Second grid binding
« Reply #3 on: March 05, 2018, 09:48:38 pm »
pqIS2 can be accessed from other script if it's defined in window scope.

Code: [Select]
window.pqIS2 = {....}