0
votes

I have the following code for my Datagrid:

    <s:DataGrid id="proveedoresGrid" top="10" bottom="10" width="426"
            creationComplete="proveedoresGrid.addEventListener('editIconClicked', itemRendererEditClickHandler);proveedoresGrid.addEventListener('deleteIconClicked', btn_eliminar_proveedor_clickHandler);"
            dataProvider="{proveedoresModel.modelo.arrayProveedores}"
            gridClick="editProveedor(event)"
            horizontalCenter="-255" requestedRowCount="4">
    <s:columns>
        <s:ArrayList>
            <s:GridColumn                       headerText="Edit" width="50" itemRenderer="renderers.EditGridRender" rendererIsEditable="false"></s:GridColumn>
            <s:GridColumn dataField="proveedor" headerText="Proveedor" width="370" editable="false"></s:GridColumn>
        </s:ArrayList>
    </s:columns>
</s:DataGrid>

Well, In the first column I have s itemrenderer that display two icons "Edit & Delete", and depending on the icon click, it dispatch an Event. The question is that such Datagrid has another general event "gridClick". Once I click on a cell from the first column, 'gridClick' event always work and and should work for any other cell not belonging to the first column.

How could I accomplish do this?

Thanks.

EDIT:

The ItemRenderer:

<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"
                width="50" height="30">

<fx:Metadata>
    [Event(name="editIconClicked")]
</fx:Metadata>

<fx:Script>
    <![CDATA[
        import events.EditItemEvent;

        import mx.controls.Alert;
        import mx.controls.DataGrid;
        override public function prepare(hasBeenRecycled:Boolean):void {}

        protected function btn_edit_clickHandler(event:MouseEvent):void {
            event.stopImmediatePropagation();
            event.stopPropagation();
            dispatchEvent(new Event("editIconClicked", true, true));
        }
        protected function btn_delete_clickHandler(event:MouseEvent):void {
            event.stopImmediatePropagation();
            event.stopPropagation();
            dispatchEvent(new Event("deleteIconClicked", true, true));
        }

    ]]>
</fx:Script>

<s:HGroup width="100%" height="24" top="3" gap="1">

    <s:Image id="btn_edit" horizontalCenter="0"
             source="@Embed('assets/images/edit_icon.png')"
             verticalCenter="0"
             click="btn_edit_clickHandler(event)"/>

    <s:Image id="btn_delete" horizontalCenter="0" 
             source="@Embed('assets/images/delete_icon.png')"
             verticalCenter="0"
             click="btn_delete_clickHandler(event)"/>

</s:HGroup>

1
Would you be more specific? What is your problem? Are the two events generated properly? - Anton
I want to be able to distinguish between gridClick event and the event from the itemRenderer launched when a cell from 1st column clicked. In this situation, both events launch. - Apalabrados
But the events are different and you can distinguish between them through their names, can't you? - Anton
Could you post your ItemRenderer's code? - Anton
I can distinguish between them but the fact is that the two events are launched. @Anton I have posted the ItemRenderer code. - Apalabrados

1 Answers

0
votes

At least I could solve my issue.

I did not know that I could get the columnIndex when clicked the DataGrid and base on this, I could prevent that GridClick event run and in case the columnIndex were 0 it means that one of the two images were clicked.