Anchoring to the top by default seems incrediibly counter-intuitive to me,
but it seems from your language that it's purposeful behavior.

By "both" I meant to anchor to the users selection if they have selected
something, and if they haven't selected anything, to stay put. That is what
I would expect the sane behavior to be, but I can make it do that (thanks to
your nudge to the right function to read/override) since the current
behavior is indeed intentional.

Daniel

On 4/6/07, Alex Harui <[EMAIL PROTECTED]> wrote:

 It jumps even without selection, but that's probably because the anchor
is set to the top, and that's what we try to keep in the view.



I don't think you can do "both", you either follow some item around and
see jumping, or you stay locked to some vertical scrollposition.


 ------------------------------

*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Daniel Grace
*Sent:* Friday, April 06, 2007 10:06 AM
*To:* [email protected]
*Subject:* Re: [flexcoders] DataGrid Jumping



I tried your method and it failed to have any effect that I could see. I
read the source to the function that you were having me somewhat override
the behavior of, eventually gave up understanding that, and came up with my
own hacked solution.

protected override function collectionChangeHandler(event: Event): void {
  var oldScrollPosition: Number = this.verticalScrollPosition;
  super.collectionChangeHandler(event);
  // My hopes is that by only restricting downward movements I'm avoiding
potential problems with the
  // list shrinking and it trying to auto-scroll UP for me. I haven't seen
it scroll up in a case I didn't want it to.
  if (oldScrollPosition < this.verticalScrollPosition) {
    this.verticalScrollPosition = oldScrollPosition;
  }
}

This has the unfortunate side effect of not following an item that the
user really has selected, but in this particular application that feature is
secondary to sitting and watching the top of the list, which is made very
difficult with the current behavior. I think that this could be extended to
incorporate both behaviors if I dug around in the documentation for enough
internal variables. Not sure what to do about multiple selection.

Alex, can you confirm if you saw the jumping behavior with no row selected
at all? If not, it may have been fixed as a side-effect of another fix in an
update, and this hack of mine would be entirely unnecessary.

Daniel

On 4/5/07, *Daniel Grace* <[EMAIL PROTECTED]> wrote:

"We do try to keep the selected item in view."

The thing is though that I don't have a selected item. Do you only see it
when there is a selected item? I will look at the variables/functions you've
pointed me at tomorrow. Thanks for the help and speedy replies. I see that
the good things I've heard about Adobe's treatment of Flex were spot on.



Daniel

On 4/5/07, *Alex Harui* < [EMAIL PROTECTED]> wrote:

I ran the test case.  I see it jump, and it should if you're sorted on the
column.  We do try to keep the selected item in view.  I think I saw it not
keep it in view once or twice so that might still be a bug, but would expect
jumping if the sorted column data is being changed.



We hit the lower-level scrollposition so that's why your handler didn't
get called.



One way to block it might be to subclass, overrride
collectionChangeHandler, and on REFRESH, set anchorBookmark to null before
calling super and restore it afterwards.



-Alex


 ------------------------------

*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Daniel Grace
*Sent:* Thursday, April 05, 2007 3:32 PM
*To:* [email protected]
*Subject:* Re: [flexcoders] DataGrid Jumping

After more fully evaluating the problem, the simple test case that I wrote
DOES exhibit the behavior when I follow all requisite steps:

1) Load the flash
2) Sort by the only field

The sorting appears to be necessary. It seems to me, from watching, that
when the first row moves off of the screen, the viewport moves to keep the
old first row to be the first row in the viewport. After that, that
particular row is no longer followed, but it will jump subsequent times,
perhaps to try and follow the new first-row, when it moves away from being
the first row? Either way, with sorting on this example using all native
Flex components jumps around like crazy.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml "
layout="absolute" applicationComplete="appComplete();">
    <mx:DataGrid dataProvider="{ac}" width="100%" height="100%">
        <mx:columns>
            <mx:DataGridColumn headerText="Testing" dataField="timer" />
        </mx:columns>
    </mx:DataGrid>
    <mx:Script>
        <![CDATA[
            import mx.utils.ObjectProxy;
            import mx.collections.ArrayCollection;
            import flash.utils.Timer;
            import mx.core.Application;

            public var t: Timer = new Timer(1000);
            [Bindable]
            public var ac: ArrayCollection = new ArrayCollection([
                new ObjectProxy({'name': 'Test 1', 'timer': 0}),
                new ObjectProxy({'name': 'Test 1', 'timer': 0}),
                new ObjectProxy({'name': 'Test 1', 'timer': 0}),
                new ObjectProxy({'name': 'Test 1', 'timer': 0}),
                new ObjectProxy({'name': 'Test 1', 'timer': 0}),
// Repeat enough times to make this take up more than one screen... or
just shrink your window
                new ObjectProxy({'name': 'Test 1', 'timer': 0}),
                new ObjectProxy({'name': 'Test 1', 'timer': 0})]);

        private function appComplete(): void {
            this.t.addEventListener("timer", this.doTick);
            this.t.start();
        }

        private function doTick(e: Event): void {
            for (var i: Number = 0; i < Application.application.ac.length;
i++) {
                Application.application.ac.getItemAt(i).timer += (
Math.random() * 10) - 5;
            }
        }
        ]]>
    </mx:Script>
</mx:Application>

Daniel

On 4/5/07, *Daniel Grace* <[EMAIL PROTECTED]> wrote:

Just to repay the quick reply to my email, you should know that a very
quck test case failed to replicate the bug without the rest of my framework
involved. I have also noticed a few more things about this bug. First, it
only happens if I have a sorted field (I don't do any custom sorting, and it
happens at least with String sorting, which is the most common field anyone
sorts on in this application) and it mostly happens when the text I am
sorting on has changed somewhere (unfortunately, that's common enough that I
can't be sure that's part of the true cause). I don't have lines selected at
the time. I created a function to try and find the bug (in a DataGrid
subclass):

            public function set veriticalScrollPosition(n: Number): void {
                Application.application.logError("Setting scroll position
to " + n);
                super.verticalScrollPosition = n;
            }

Note that this failed to ever run, even when I saw the bug happen. Are
there any other functions that could trap when this bug is rearing its head?
I like having the source to most/all of the framework for when something
like this happens, but there sure is a lot of code to try and understand.

Daniel



On 4/5/07, *Alex Harui* < [EMAIL PROTECTED]> wrote:

I don't remember any bugs like that.  Can you build a small test case that
uses regular DataGrid?


 ------------------------------

*From:* [email protected] [mailto: [EMAIL PROTECTED] *On
Behalf Of *Daniel Grace
*Sent:* Thursday, April 05, 2007 12:40 PM
*To:* [email protected]
*Subject:* [flexcoders] DataGrid Jumping

I am using a DataGrid that is mostly stock (overrode drawRowBackground
and set dataProvider. This particular datagrid has a lot of
information in it that changes every second. That's all fine.

If there is a vertical scroll bar (common) and I am scrolled to the
top, with no rows selected, it will periodically jump down to what
appears to be roughly the halfway point. This seems to happen when
something changes (and happened a lot less frequently before I put the
timers in). There is a chance that I have messed something up, but I
doubt it. I know that it happened before I overrode set dataProvider.

My real question is -- is this addressed in the hotfix? I don't see
specific mentioning of it on
http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=kb401224 ,
though there are fixes in the datagrid. After seeing a few problem
reports here I'm not overly eager to install the hotfix if it is not
going to fix a problem that I am having (also, the page referenced
suggests this strategy).

Or, does anyone know what might be causing my scroll position to jump,
without overriding any functions that would logically cause such a
behavior?

Daniel











Reply via email to