Hi,
I need a way to update calculations everytime the visble rows in a ListGrid change due to scrolling or component resizing. I see the getVisibleRows function for ListGrid. But, I’m not clear on how to force a call to getVisibleRows as the visibler ows change due to scrolling or resizing so I can re-run my calculations on only the visible rows?
Hi senordhuff,
The simplest way to do this is probably to perform the calculations whenever a given row is rendered, for example, perform them when formatCellValue is called for the first cell in the row.
Hi, I think the issue with that approach is I need a way to turn off the calculations when the row is no longer visible.
How do you mean “turn off”? If you are hooking formatCellValue(), you won’t be called again until user scrolling causes a new range of rows to be rendered. If you are triggering calculations by some external event as well (eg streaming data), then you can use getVisibleRows() to avoid recalcs.
It would probably be most helpful to explain exactly what I"m trying to do. I am trying to implement the following functionality with Lightstreamer that you see in this demo (http://app.lightstreamer.com/GridDemo/). In order to do it, I need a way to track which items are visible and only keep those rows active with Lightstreamer.
That makes much more sense.
We would suggest:
- gathering a list of the rowNums for all rendered rows in an Array via hooking formatCellValue() [rendered rows can differ from visible rows due to draw ahead]
- overriding redraw() on the grid, call Super, and using the Array of rendered rows to configure LightStreamer.
Hi there, I’m finally ready to try implementing this. I’m trying to override redraw() as you propose but perhaps I’m doing something wrong because my debug statement below is never firing when I resize my window or fetch new data for the grid.
redraw: function(){
isc.Log.logDebug("redrawn");
this.Super("redraw", arguments);
},
Is tat the correct way to override redraw() for a ListGrid?
Yes, but logging at debug level (via logDebug) won’t show anything unless you’ve configured the “Log” category to DEBUG level.. is that the issue?
Yes, I tried logInfo and even the good ole alert() and nothing is displaying when attempting to redraw the grid by fetchingData or changing the size of the grid or changing the window size. It sounds like those things should make redraw fire? I’m using 5.7.1.
Hi Dave,
Sorry, there’s a mistake in the original suggestion - the ListGrid as a whole won’t redraw in this case, just the body. So to catch redraw, you could observe() grid.body.redraw.
Hi, I’m not exactly clear on how to use observe(). Would I need to create another object for the sole purpose of observing the grid.body? Or, could I observe the grid.body from the grid itself? I tried the following and got an error message stating "Invalid observation: Target is not an object. "
fundAssetsGrid.observe(fundAssetsGrid.body,"redraw","isc.Log.logInfo('here');");
But, I did change my Component Log settings to debug for all redraws on the body. And, I noticed it is not redrawing when the user scrolls down to render new rows. So, I’m not sure that redraw is going to achieve the effect we are after. We want to conserve the bandwidth our application is using by only streaming data from Lightstreamer to the client for the rows that are actually visible. So, if they scroll down, then the rows no longer visible will be unsubscribed and the new rows that are visible will become subscribed. This way, we’ll only have perhaps 25-30 subscriptions to Lightstreamer at any one time and we won’t be wasting bandwidth streaming data the user can’t see anyway. Perhaps we’d add in a buffer of x rows on each side.But, I’m not sure if redraw() is the best method to observe since it doesn’t seem to fire on scroll. Ideas?
Hi Dave,
Your observation is correct, but in order to observe the body you will need to perform it after draw. Also, you have an extra space in “redraw”.
Watching the logs for this example shows the expected redraws on scrolling. You can watch the corresponding local example in the Feature Explorer in your SmartClient SDK. If you aren’t see redraws in your live application, you may have either disabled incremental rendering (showAllRecords:true) or set a high drawAheadRatio.
Hi, I’m almost there with this functionality. The only issue I’m still trying to solve is the initial loading of the Lightstreamer tables. Previously, we were using the dataArrived event to load Lightstreamer tables for all data arriving. However, with this change, we don’t want to load a Lightstreamer table for all data arriving but just those rows that will be drawn. I’m not observing that redraw is fired automatically after dataArrived though. So, I need a way to force a call to load only the drawn tables at some point during or after the dataArrived event in the event that redraw isn’t caused by the user. Any ideas?
Actually, nevermind, I figured it out. I was waiting until after the dataArrived to do the initial draw. So, I just had to call the same function I observe after the initial draw and we are good. Thanks for all your help with this.