jQWidgets Forums
jQuery UI Widgets › Forums › Grid › grid datasource recordstartindex
Tagged: grid, jqxgrid, recordendindex, recordstartindex, scrolloffset, scrollto, updatebounddata
This topic contains 12 replies, has 4 voices, and was last updated by Peter Stoev 11 years, 1 month ago.
-
Author
-
Hi,
I have a few problem related to (re)loading data for my grid. I use a grid in virtualmode, no paging with a synchronous dataAdapter. On reloading the grid content I use ‘updatebounddata’. The problem occurs when my existing grid is scrolled down. This causes the grid’s recordstartindex to be non-zero (which is ok, it’s used by the server side to determine a record offset). However, the updatebounddata does not reset the recordstartindex (and recordendindex). This causes problems with the newly loaded dataset, it shows at the (wrong) offset related to the previous data.
I fixed this by manually resetting the recordstart/endindex before the reload. This is of course an invalid fix because it may set the grid internals to an invalid state. As it now turns out this indeed caused another problem to occur. So, I need another way to solve the recordstartindex problem.
My question therefore is: how can the grid offset state be properly reset before an updatebounddata. Note: jqxGrid(‘scrollto’, 0, 0) did not do accomplish this.
Ton
Hello Ton,
In virtual mode updatebounddata is called when the grid is scrolled. The recordstartindex and recordendindex are also updated automatically. If you manually call the scrollto method (which is now deprecated, use scrolloffset instead), updatebounddata is also called, so there is no need to call it manually.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
The situation is a bit different. The problem is with updateboundata if I manually call it to refresh or otherwise change the grid content. And the problem occurs if at that moment the grid content is scrolled. In that case, the call that I make to updatebounddata does not reset recordstartindex. So, new data comes in due to my call but it is displayed at the previous offset (and the previous offset is also used in the call itself). For example:
I have data loaded in my grid that has records 1 – 20. I scrolled 2 record down so record 3 is the topmost visible. Now, I change some parameter (e.g. I filter for odd rows only) and call updatebounddata. The call goes out to my server which needs to return record 1, 3, 5, etc. However, my server also receives recordstartindex 3 so it returns records 5, 7, 9, etc. instead.
What I would like in this case is that the updatebounddata resets the recordsstartindex (and possibly related variables) to zero.
Ton
Hi Ton,
You should turn off your manual call of updateboundata during scrolling. The recordstartindex and recordendindex are updated and updateboundata is called when the grid has finished scrolling.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
I don’t call updatebounddata during scrolling (it would not make a lot of sense to do that). I have a grid and at some point it was scrolled down. Then (after a user did some filter setting and clicks some reload button) I call updatebounddata to read new content. _Because_ the grid was scrolled down it (still) has a non-zero recordstartindex. This is not reset by the updatebounddata call, causing invalid data to be returned and displayed. Also see my previous explanations above.
Ton
Hi guys,
Just wanted to see if I can help here, too. If I understood correctly, the scenario is Virtual Scrolling with Filtering. If that is correct, then please download jQWidgets ver.2.8.3 from our Download page and take a look at the phpdemos/server_side_grid_filtering_and_virtualscrolling example.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi Dimitar, Peter,
Thanks for your input, I guess I’m doing something wrong in explaining my issue. Let me try again to see if I can explain it properly. The issue is not related to filtering, I used that as an example to indicate my problem is related to a grid data reload that brings in new content.
My problem:
1. I have a grid loaded with data – all fine.
2. The grid is scrolled down a bit (causing a few server calls), recordsstartindex is non-zero – all fine
3. I now manually execute an updatebounddata (I want to reload the grid with some new data)At 3 things goes wrong: the recordstartindex was non-zero at step 2 (ok). But for step 3 I need it (the recordstartindex) to be zero since my new data is unrelated to the data at steps 1 and 2. However, the updatebounddata does not internally reset the recordstartindex to zero. So, whats happens at 3 is: ‘load new data but load it at the offset from step 2’.
To fix this I did:
3a: .recordendindex -= .recordstartindex; .recordstartindex = 0;
3b: call updatebounddataThis fix solved my problem. However, I now (I fixed this weeks ago) run into a new problem which is caused by some kind of internal grid issue. Which is logical because in step 3a I interfere with grid internal data.
So, since fix 3a is no longer working I need another solution. Most likely it would seem to me that the grid should – when updatebounddata is called – reset recordsstartindex (and related values, e.g. the internal datasource copy).
Ton
Hi,
“updatebounddata” will rebind the Grid taking into account the scroll position and some other settings. To make a full data source refresh, you need to set the “source” property to a new instance of jqxDataAdapter. That will make a full re-render.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi Peter,
That makes sense, thanks for clearing this up.
One more question: wouldn’t this also apply when some filter is set? Let’s say I have 20 records when not filtered and I’m at offset 10 (due to scrolling). Then I set some filter which will cause only 5 records to be available. The server wil then find no records since the offset is beyond the new record set, causing zero records to be returned (while actually records are available).
To prevent his situation, the updatebounddata should never be used in situations like this. In other words, only use updatebounddata if you expect new records to be added at the end of the existing record set and don’t apply any filtering, change in order, etc. Is that a correct interpretation?
Ton
Hi,
The reason that I pointed you to the sample is that it shows how to make a Grid with Virtual Scrolling and how to enable Filtering and Sorting in such Grid. If you take a look at the sample, you will note that the ‘updatebounddata’ is called with additional ‘filter’, and ‘sort’ parameters for handling filtering and sorting scenarios.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hi Peter,
I studied the samples (including this one) a few times in the past. The server_side_grid_filtering_and_virtualscrolling seems to confirm my previous comment. The server side uses the recordsstartindex as the ‘LIMIT $start, $total_rows’ value for the query (meaning the starting point where 0 is the first record).
So, as far as I understand the sample code suffers from the exact situation I described above. When I set a filter that does have records but less than the recordstartindex is returns zero records. The sample should not use updatebounddata but set the source property instead.
Ton
Hi,
I have problem on “updatebounddata”.
Initially the Grid loads with correct width, no problem on that.
For Redisplaying the Grid, we call updatebounddata,it loaded the grid its fine.
But the problem for is , The grid gets shrinked into smaller size
(Let say intial Grid width is 100%, After applying updatebounddata it gets changed as 60%).Kindly suggest me
Regards
IyanarHi Iyanar,
Please, share a sample using http://jsfiddle.net/ which demonstrates your scenario.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.