Author Topic: Get list of rows which is visible in grid with lazy/remote loading  (Read 501 times)

pranit@srcomsec

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
Please advise how to get a list of rows visible on the grid.

For example, the data model with gird is 2000 rows, the grid height can be changed anytime.

If the grid shows 20 rows after adjusting the height then it returns 20 rows only, If the grid shows 30 rows after adjusting height then returns 30 rows.



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Get list of rows which is visible in grid with lazy/remote loading
« Reply #1 on: November 21, 2022, 06:49:21 am »
Visible row indices can be obtained by getViewPortIndx method.

https://paramquery.com/pro/api#method-getViewPortIndx

pranit@srcomsec

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
Re: Get list of rows which is visible in grid with lazy/remote loading
« Reply #2 on: November 22, 2022, 05:54:59 pm »
Thank you for this, with this method we are getting an index of the start and end rows. If we need to get data for the start & end row index then we need to loop and get all details.

I am using the method below to get these rows. Please advise if you see this is not correct.
Code: [Select]
var loGridSymbols = $("#gridfilter1").pqGrid("getData", { dataIndx: ['stExchange', 'stSymbol', 'pq_empty'] });
var loActiveRows = loGridSymbols.filter((x) => { return x.pq_empty == false; });

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Get list of rows which is visible in grid with lazy/remote loading
« Reply #3 on: November 22, 2022, 07:25:00 pm »
That's incorrect.

Row data can be obtained from rowIndx by pageData[ rowIndx ]. So first and last visible row in the viewport can be obtained as:

Code: [Select]
var pageData = grid.pageData();
var firstRow = pageData[ obj.initV ];
var lastRow = pageData[ obj.finalV ];

where obj is returned by getViewPortIndx method.

pranit@srcomsec

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
Re: Get list of rows which is visible in grid with lazy/remote loading
« Reply #4 on: November 22, 2022, 08:32:34 pm »
Thank you for your quick response.

As per your suggestion, we can get 1st and last row's details. We need all rows data between the start (obj.initV) and end row (obj.finalV) index.

Let me know if you have any suggestions.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Get list of rows which is visible in grid with lazy/remote loading
« Reply #5 on: November 22, 2022, 09:55:47 pm »
you can get all rendered rows as an array with slice method.

Code: [Select]
  var renderedRows = pageData.slice( initV, finalV+1);
« Last Edit: November 22, 2022, 10:15:12 pm by paramvir »

pranit@srcomsec

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 99
    • View Profile
Re: Get list of rows which is visible in grid with lazy/remote loading
« Reply #6 on: November 23, 2022, 12:32:23 pm »
That is perfect!

Thank you very much.