Comunidad de diseño web y desarrollo en internet online

Agregar renglones a un datagrid, flex

Citar            
MensajeEscrito el 04 Abr 2008 09:05 pm
Hola colegas del foro, despues de leer por varios lugares ya estoy entendiendo un poco esto de flex, asi que he logrado armar esta aplicacion http://bp0.blogger.com/_8FSqsDcCA-Y/R_aXaiveafI/AAAAAAAAACs/lLTOcNc2SDM/s1600-h/GridDinamico.JPG sobre platillos donde en una HorizontalList Muestro los diferentes tipos de platillos, abajo tengo un datagrid donde ire almacenando los platillos que se han escogido y a un lado un TileList donde segun el tipo de platillo que han escogido en la HorizontalList muestro los platillos correspondientes, esta lista de platillos le habilite la opcion arrastrar y al datagrid la opcion de recibir datos, de tal manera que si arrastro un elemento del TileList al Datagrid este va agregando los platillos.

Hasta aca todo bien, pero ahora lo que intento hacer es que al darle doble click (o click no importa) a un elemento del TileList se agregue (lo mismo que se hace cuando se arrastra) al Datagrid donde voy elegiendo los platillos... aca es donde pido la ayuda de alguien que pudiera indicarme como hacerle.

Bien a continuacion un ejemplo de los datos que me regresa el archivo TodosPlatillos.php

Código :

<Platillos>
   <Tipo id="10" descripcion="Aderezos">
      <Platillo id="139" descripcion="Aderazo Italiano" precio="10.00"/>
      <Platillo id="137" descripcion="Aderezo Cesar" precio="10.00"/>
      <Platillo id="138" descripcion="Aderezo Ranch" precio="10.00"/>
   </Tipo>
   <Tipo id="18" descripcion="Antojos">
      <Platillo id="246" descripcion="Alitas" precio="64.00"/>
      <Platillo id="248" descripcion="Chiles Jalapenos Rellenos" precio="54.00"/>
      <Platillo id="247" descripcion="Hongos al Ajillo" precio="64.00"/>
   </Tipo>
</Platillos>

Y a continuacion mi codigo MXML


Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
   creationComplete="xmlPlatillos.send();  myHList.automationValue">
   <mx:HTTPService id="xmlPlatillos" url="http://localhost/phpclases/TodosPlatillos.php"
    showBusyCursor="true" resultFormat="e4x"> 
      <mx:request>
         <TipoPlatillo>4</TipoPlatillo>   <!--Solo me traigo las bebidas el servico debe tener la propiedad method="POST"-->
      </mx:request>
   </mx:HTTPService>
<mx:Script>
<![CDATA[
   import mx.controls.dataGridClasses.DataGridListData;
    import mx.controls.Alert;
    import mx.collections.*;

     /*Agrega el platillo seleccionado de la izquierda al grid de la derecha*/
   public function AgregaPlatillo(Plato):void
   {
         
   }
   
]]>
</mx:Script>
   <mx:HorizontalList id="myHList"
      dataProvider="{xmlPlatillos.lastResult.Tipo}"
      labelField="@descripcion" dataTipField="@descripcion"
      change="myTList.dataProvider=myHList.value.Platillo;"
       click="myTList.dataProvider=myHList.value.Platillo;"
       showScrollTips="true" showDataTips="true" 
      selectedIndex="0" columnWidth="100" width="100%"  height="68"
      />
   <mx:HDividedBox x="10" y="76" width="100%">
      <mx:DataGrid id="GridPlatillos" height="236" width="50%"      
      showScrollTips="true" dataTipField="@platillo" toolTipShow="true" 
      dropEnabled="true"   selectedIndex="0"
      >
         <mx:columns>
            <mx:DataGridColumn headerText="Id" dataField="@id" width="100"/>
            <mx:DataGridColumn headerText="Platillo" dataField="@descripcion"/>
            <mx:DataGridColumn headerText="Precio" dataField="@precio" width="100" textAlign="right"/>
         </mx:columns>
      </mx:DataGrid>
      <mx:TileList id="myTList" 
         labelField="@descripcion" showDataTips="true" dataTipField="@descripcion"
         width="50%" direction="horizontal" textAlign="left"  
         height="238" columnWidth="{(myTList.width / 2) - 10}"
       dragEnabled="true" dragMoveEnabled="false"
         selectedIndex="0" doubleClickEnabled="true"          
          showScrollTips="true" variableRowHeight="true"
          doubleClick="AgregaPlatillo(myTList.value)"           
      />
   </mx:HDividedBox>
</mx:Application>

Cualquier ayuda posible sera muy agradecida, de hecho estoy pensando en liberar el codigo completo de mi aplicacion cuando termine, pero primero quiero dejar un programa funcional.
De nuevo el link donde se puede ver lo que llevo hasta ahora funcionando http://bp0.blogger.com/_8FSqsDcCA-Y/R_aXaiveafI/AAAAAAAAACs/lLTOcNc2SDM/s1600-h/GridDinamico.JPG:
[/url]

Por sergestux

49 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 04 Abr 2008 09:17 pm
He visto ejemplos como el siguiente pero no logro adaptarlo a mis necesidades...

Código :

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="initData()">
    <mx:Script><![CDATA[
    import mx.collections.*;
    private var DGArray:Array = [
    {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99},
    {Artist:'Pavement', Album:'Brighten the Corners', Price:11.99}];
    [Bindable]
    public var initDG:ArrayCollection;
    //Initialize initDG ArrayCollection variable from the Array.
    public function initData():void {
    initDG=new ArrayCollection(DGArray);
    }
    public function addNewItem():void {
    var o:Object;
    o = {Artist:'Pavement', Album:'Nipped and Tucked', Price:11.99};
    initDG.addItem(o);        /*ACA SE AGREGA EL NUEVO RENGLON*/
    callLater(focusNewRow);    /*esto se ejecuta despues de agregar el renglon*/
    }
    public function focusNewRow():void {
    myGrid.editedItemPosition = {
    columnIndex:0,rowIndex:myGrid.dataProvider.length-1
    };
    }
    ]]></mx:Script>


    <mx:DataGrid id="myGrid" width="350" height="200" dataProvider="{initDG}"
    editable="true">
        <mx:columns>
        <mx:Array>
            <mx:DataGridColumn dataField="Album" />
            <mx:DataGridColumn dataField="Price" />
        </mx:Array>
        </mx:columns>
    </mx:DataGrid>
    <mx:Button id="b1" label="Add New Item" click="addNewItem()"/>
</mx:Application>

Por sergestux

49 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 04 Abr 2008 09:44 pm
Ya lo solucione y no fue tan dificil como creia, le agregue una coleccion de arreglos al datagrid

Código :

      <mx:ArrayCollection id="ArregloData">
      </mx:ArrayCollection>

y cuando hago doble click en la TileList hago lo siguiente

Código :

doubleClick="{ArregloData.addItem(myTList.value)}"      

A continuacion el codigo semicompleto...

Código :

      <mx:DataGrid id="GridPlatillos" height="236" width="50%"      
      showScrollTips="true" dataTipField="@platillo" toolTipShow="true" 
      dropEnabled="true"   selectedIndex="0"
      >
      <mx:ArrayCollection id="ArregloData">
      </mx:ArrayCollection>
         <mx:columns>
            <mx:DataGridColumn headerText="Id" dataField="@id" width="100"/>
            <mx:DataGridColumn headerText="Platillo" dataField="@descripcion"/>
            <mx:DataGridColumn headerText="Precio" dataField="@precio" width="100" textAlign="right"/>
         </mx:columns>
      </mx:DataGrid>
      <mx:TileList id="myTList" 
         labelField="@descripcion" showDataTips="true" 
         dataTipField="@descripcion@precio"
         width="50%" direction="horizontal" textAlign="left"  
         height="238" columnWidth="{(myTList.width / 2) - 10}"
       dragEnabled="true" dragMoveEnabled="false"
         selectedIndex="0" doubleClickEnabled="true"          
          showScrollTips="true" variableRowHeight="true"
          doubleClick="{ArregloData.addItem(myTList.value)}"           
      />

Por sergestux

49 de clabLevel



Genero:Masculino  

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.