10 Replies Latest reply on Oct 18, 2011 12:43 PM by tojira

    How to avoid doubleclick event on a datagrid scrollbars?

    pbesi Level 1

      Hello.

      I've a datagrid.

       

      I need a doubleclick event cliccking on a data grid row.

      I've enabled the doubleclick event. It works fine, when the user doubleclicks on a row, an event happens! In my case I open a modal window. Great!

       

      Now the problem:

      The problem arises when the user clicks in a short time on a data grid scroll bar (both horizontal or vertical). In this case a double click event is dispatched.

      But his intenton is just to scroll the grid, no more.

      Please, notice that the dobule click on a scrollbar is a well-known action that can be performed in all the applications and operating systems.

       

      I neet the "double click" event just on a data grid rows and not on its scrollbars. Cliccking twice or more on the scrollbar I just want to scroll the grid. How can avoid to dispatch an event?

       

      Thank you

      Pbesi

        • 1. Re: How to avoid doubleclick event on a datagrid scrollbars?
          kokorito Level 4

          cant you just check the target of the double click event? If the target is an itemRender then do your thing, if not then dont

          • 2. Re: How to avoid doubleclick event on a datagrid scrollbars?
            pbesi Level 1

            Hello kokorito,

             

            yes, you're right! More precisaly because I'm working with spark datagrid, I've to check if the target is a DefaultGridItemRenderer object type.

             

            Thank you

            Pbesi

            • 3. Re: How to avoid doubleclick event on a datagrid scrollbars?
              tojira

              Thanks for the tip!  Just to help the next guy that comes along, you need to check event.target in this case.  I am used to always checking event.currentTarget.  In this situation, currentTarget is always of type "DataGrid" and doesn't help you at all. 

              • 4. Re: How to avoid doubleclick event on a datagrid scrollbars?
                pbesi Level 1

                tojira wrote:

                 

                Thanks for the tip!  Just to help the next guy that comes along, you need to check event.target in this case.  I am used to always checking event.currentTarget.  In this situation, currentTarget is always of type "DataGrid" and doesn't help you at all. 

                Tojira, I confirm what you wrote.

                Here my code:

                 

                [code]

                 

                if(event.target is DefaultGridItemRenderer)

                {

                .....your code

                }

                [/code]

                 

                More...

                In the case you've your customized itemrender in a column, the code is:

                 

                [code]

                if(event.target is DefaultGridItemRenderer || event.target is YourItemRender){

                ......

                }

                 

                [/code]

                 

                 

                Pbesi

                • 5. Re: How to avoid doubleclick event on a datagrid scrollbars?
                  tojira Level 1

                  I was returning today to add something about custom item renderers but you beat me to it, Pbesi.   I have a custom gridItemRenderer which I now have to check for just as you demonstrated above.  What I don't understand is why I can't just do this:

                   

                  if( event.target is IGridItemRenderer )  //Should be true for both default and custom

                   

                  My custom renderer implements the IGridItemRenderer interface, but when I double click one in the grid, the event.target is not myCustomGridItemRenderer, it is GridLayer.  So what I have to do is this:

                   

                  if( (event.target is IGridItemRenderer) || (event.target is GridLayer) )

                   

                  I presume this would work for all custom gridItemRenderers, but I only have one, so I haven't tested this.  Any idea why GridLayer is the type of the event target?  My custom renderer is very simple.  It just renders Booleans as "Yes/No" rather than "True/False"

                   

                  <s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                        xmlns:s="library://ns.adobe.com/flex/spark"
                        xmlns:mx="library://ns.adobe.com/flex/mx"
                        clipAndEnableScrolling="true"
                        implements="spark.components.gridClasses.IGridItemRenderer">

                        <fx:Script>
                             <![CDATA[
                                  override public function prepare(hasBeenRecycled:Boolean):void {
                                       lblData.text = (data[column.dataField] == true) ? "Yes" : "No" ;
                                                          }
                                                ]]>
                       </fx:Script>

                        <s:Label id="lblData" top="9" left="7"/>

                  </s:GridItemRenderer>

                  • 6. Re: How to avoid doubleclick event on a datagrid scrollbars?
                    Flex harUI Adobe Employee

                    An event target has to “own” the pixels you click on by having drawn something there (even with alpha=0) or by placing a child who has drawn something there.  The Label in your renderer won’t own pixels beyond the text it is displaying so clicking there will fall through to the GridLayer parent.

                    • 7. Re: How to avoid doubleclick event on a datagrid scrollbars?
                      kevinklin Adobe Employee

                      Are you listening for the "doubleClick" event? Try listening for the "gridDoubleClick" event instead. These should only be dispatched when you interact with the Grid.

                      • 8. Re: How to avoid doubleclick event on a datagrid scrollbars?
                        tojira Level 1

                        I didn't know about gridDoubleClick before.  While it is an improvement in that it does prevent the problem of double-clicking on a scrollbar or scrollbar button, it is not a complete solution because the problem can still arrise by clicking on the grid header row (column names).  If there is no row selected yet, the same null reference error occurs.

                        • 9. Re: How to avoid doubleclick event on a datagrid scrollbars?
                          kevinklin Adobe Employee

                          You can just check if the GridEvent has a null "item" property. headers won't have an "item". Where do you get a null reference error? what's the call stack?

                          • 10. Re: How to avoid doubleclick event on a datagrid scrollbars?
                            tojira Level 1

                            Thank you, kevinklin, that did the trick.  Here's the full story.  Originally, when I was tryign to stop double-clicks on scrolbars, I was checking:

                             

                            if( event.target.selectedItem != null )

                             

                            This was producing a null reference error in the selectedItem getter function within DataGrid.as.  At that time, there was no event.item because I was using the doubleClick event, which is MouseEvent.  Then, when I switched from using the doubleClick event to the gridDoubleClick event, I did not modify my listener function.  The original function was stubbed out by FlashBuilder and took an argument of event:MouseEvent.  There is no item on this type of event and so the code hinting did not show it to me.  Also, when I tried using your suggestion intially, it would not compile.  I realized this error and changed it to event:GridEvent and now it works like a charm.

                             

                            Thank you everyone!!

                             

                            So the final code is a listener function firing on gridDoubleClick as follows:

                             

                            protected function myDataGrid_doubleClickHandler(event:GridEvent):void {

                                 if( (event.item != null) )

                                      dispatchEvent(new myEvent(EVENT_TYPE, event.currentTarget.selectedItem.id, true));

                            }