Comunidad de diseño web y desarrollo en internet online

Agregar Filas de un Datagrid a otro Datagrid

Citar            
MensajeEscrito el 28 Jul 2008 04:06 pm
Hola , acudo a uds si alguien le paso esto y lo pudo solucionar, tengo dos datagrid y en el medio dos botones(boton 1 y boton 2) , al hacer click en un boton1 pasar la info del datagrid 1 al datagrid 2 y viceversa con el boton 2, probe usando dropEnabled="true" dragEnabled="true" dragMoveEnabled="true" en el datagrid pero este solo arrastra , lo que quiero hacer es poder hacer click en un boton y se comporte igual.

Saludos

Por pchavez

18 de clabLevel



 

msie
Citar            
MensajeEscrito el 28 Jul 2008 08:25 pm
Los datos de un datagrid provienen de un arrayCollection, asi que sustraer la fila que quieres [del ArrayCollection] y agregarsela al otro ArrayCollection del otro datagrid, seria suficiente para realizar lo que quieres.

Código :

<mx:DataGrid x="24" y="35" dataProvider="{ grid1 }" id="mygrid1">
      <mx:columns>
         <mx:DataGridColumn headerText="Column 1" dataField="nombre" />
         <mx:DataGridColumn headerText="Column 2" dataField="edad" />
      </mx:columns>
   </mx:DataGrid>

   <mx:DataGrid x="320" y="35" dataProvider="{ grid2 }" id="mygrid2">
      <mx:columns>
         <mx:DataGridColumn headerText="Column 1" dataField="nombre"/>
         <mx:DataGridColumn headerText="Column 2" dataField="edad"/>
      </mx:columns>
   </mx:DataGrid>
   <mx:Button x="234" y="58" label="--]" height="38" click="{ pasarDerecha() }"/>
   <mx:Button x="234" y="115" label="[--" height="39" click="{ pasarIzquierda() }"/>
   <mx:Script>
      <![CDATA[
         import mx.collections.ArrayCollection;
         import mx.controls.Alert;
         
         [Bindable] public var grid1:ArrayCollection = new ArrayCollection();
         [Bindable] public var grid2:ArrayCollection = new ArrayCollection();
         
         function init()
         {
            var miO:Object;
            for(var i:int=0;i<4;i++)
            {
               miO = new Object();
               miO.nombre = "Estudiante_"+i.toString();
               miO.edad = i;   
               grid1.addItem(miO);
               grid2.addItem(miO);
            }
         }
         
         function pasarDerecha()
         {
            if(mygrid1.selectedItem)
            {
               var temp:Object = mygrid1.selectedItem;
               grid2.addItem(temp);
               grid1.removeItemAt( mygrid1.selectedIndex );
               grid1.refresh();
               grid2.refresh();   
            }
         }
         
         function pasarIzquierda()
         {
            if(mygrid2.selectedItem)
            {
               var temp:Object = mygrid2.selectedItem;
               grid1.addItem(temp);
               grid2.removeItemAt( mygrid2.selectedIndex );
               grid2.refresh();
               grid1.refresh();   
            }
         }
      ]]>
   </mx:Script>


Espero te sirva..
salu2 ^^

Por Zandy

Claber

1345 de clabLevel

5 tutoriales

Genero:Masculino   Premio_Secretos

msie
Citar            
MensajeEscrito el 29 Jul 2008 01:32 pm
El problema en si , es con un checkbox de seleccion en ambos datagrid, porque puedo seleccionar unos cuantos y de ahi trasladar al otro datagrid, el ejemplo que me enviaste traspasa toda la info del datagrid 1 al datagrid2 y viceversa, pero para una seleccion con checkbox como lo haria porq tengo problemas con el indice

Saludos
Giovani

Por pchavez

18 de clabLevel



 

msie
Citar            
MensajeEscrito el 29 Jul 2008 02:23 pm
uhm, se traspasa la fila que marques en el datagrid..

En otro post que creaste, te daban una idea bien clara, ordenas el array de elementos seleccionados de forma descendente, y con un ciclo vas eliminando de abajo hacia arriba para que no se te corran los indices....

Por Zandy

Claber

1345 de clabLevel

5 tutoriales

Genero:Masculino   Premio_Secretos

firefox

 

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