Comunidad de diseño web y desarrollo en internet online

Crear Paginación

Citar            
MensajeEscrito el 31 Dic 2006 01:45 pm
Hola de nuevo.
Tengo una aplicación que muestra los resultados de la BBDD, mediante AMFphp (cortesía de Jorge Solís ). Seleccionas la familia y te saca los productos en el scrollPane.

Quiero cambiar este scrollPane por un sistema de paginación, de modo que muestra por ejemplo los 5 primeros resultados y con un botón de siguiente y anterior para que vaya mostrando los siguientes.
--
Podéis ver la aplicación en la siguiente web
http://sorrymama.freehostia.com/
--
Posteo también el código

Código :

import mx.remoting.Service;
import mx.services.Log;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.remoting.PendingCall; 
import mx.remoting.debug.NetDebug; 

//Initialize a Logger
mx.remoting.debug.NetDebug.initialize(); // initialize the NCD
var myLogger:Log = new Log( Log.DEBUG, "logger1" );
// override the default log handler
myLogger.onLog = function( message:String ):Void {
// trace( "myLogger-->>>"+message );
}
//IMPORTANT -> Change to the proper path
_global.svc = new Service(    
    /*"path to gateway.php",*/
    "http://sorrymama.freehostia.com/gateway.php",
     myLogger,
     "shopping",
     null,
     null); 
var pc:PendingCall = svc.getFamily(); //default method: show promotions
pc.responder = new RelayResponder(this, "getFamily_Result", "onError" );
z=0
//Hide the loading movie
sending_lc = new LocalConnection();
sending_lc.send("lc_name", "dissapear")
//The combobox is waiting for data
catList.addItem("Cargando...")
//disabled interface elements
enableInterface(false)

////////////////////////
//  Catalog handlers  //
////////////////////////
//Generic error handler
function onError(rs: FaultEvent){
   mx.remoting.debug.NetDebug.trace({level:"None", message:"There was a problem: " + fault.fault.faultstring });
}
//Receive current category
getFamily_Result = function(re: ResultEvent){
   var rs = re.result
   //disable user interaction
   enableInterface(true)
   cant = rs.length
   catList.removeAll()
   //Pass to the combobox
   for(var i=0; i<cant; i++)
      catList.addItem(rs.getItemAt(i).Name, rs.getItemAt(i).PkFamily)
   var pc: mx.remoting.PendingCall = svc.getProducts(1);
   pc.responder = new RelayResponder(this, "getProducts_Result", "onError" );
   //Main title
   Title.text = rs.getItemAt(0).Name
   pane.contentPath = "fotos"
}
getProducts_Result = function(re: ResultEvent){
   var rs = re.result
   //Clean the holder
   for(i in pane.content) pane.content[i].removeMovieClip()
   pane.hScrollPolicy = "on"
   cant = rs.length
   z = 0
   //loop trough rows to load into pane
   for(var i=0; i<cant; i++){
            
      /*p = pane.content.attachMovie("holder", "holder"+(z++), z, {_x:12+(150*int(z/4)), _y:(150*(z%4))+5})*/
      //set Pane content
      p = pane.content.attachMovie("holder", "holder"+(z++), z, {_x:45+(150*int(z/122)), _y:(150*(z%122))+15})
      //Textfield showing details
      p.createTextField("datos", 2, -20, 105, 120, 40)
      p.datos.multiline = true
      p.datos.html = true
      var txt = addBreak(rs.getItemAt(i).Name, 20)
      p.datos.htmlText = "<p align=\"center\">"+txt+"<p>"
      //external and internal holder where the image will be loaded
      p.createEmptyMovieClip("foto"+i, 1)
      p["foto"+i].createEmptyMovieClip("holder", 1)
      //load the timage
      p["foto"+i].holder.loadMovie("products/pics/"+rs.getItemAt(i).Image)
      p["foto"+i].datos = rs.getItemAt(i)
      //set the onPress handler
      p["foto"+i].onPress = function(){
         //que al pinchar parezca la ventana
         ventana1._visible = true;
         var target = this._parent._parent._parent._parent.ventana1.details
         target.datos = this.datos //Copy data 
         target.holder.loadMovie("products/photos/"+this.datos.Image)
         target.title.text = this.datos.Name
         target.details.htmlText = "<b>Modelo:</b> "+this.datos.Content+"<br><b>Peso:</b> "+this.datos.Weigth+"<br><b>Precio:</b> "+this.datos.Price
         target.cant.value = 1
      }
      //force scrollpane to show scrollBar with the new content
      pane.vScrollPolicy = "on";
   }
   //Default content of the "Details window"
   ventana1.details.holder.loadMovie("products/photos/"+rs.getItemAt(0).Image);
   ventana1.details.title.text = rs.getItemAt(0).Name
   ventana1.details.details.htmlText = "<b>Modelo:</b> "+rs.getItemAt(0).Content+"<br><b>Peso:</b> "+rs.getItemAt(0).Weigth+"<br><b>Precio:</b> "+rs.getItemAt(0).Price
   ventana1.details.datos = rs.getItemAt(0)
}

//Esto es lo que hace que se refresque el contenido al cambiar de categoria
catChoice = {}
catChoice.ref = this
catChoice.change = function(evt){
   var pc:PendingCall = svc.getProducts(evt.target.selectedItem.data)
   pc.responder = new RelayResponder(this.ref, "getProducts_Result", "onError" );         
   Title.text = evt.target.selectedItem.label
}
catList.addEventListener("change", catChoice)   

//Esto hace referencia a nombre de los productos que saca el scrollPane
function addBreak(texto, ancho){   
   texto += " ";
   var temp = "", first = 0;
   var linea = ancho;
   while(temp.length<texto.length){
      while (texto.charAt(linea)!=" ") linea--;
      temp += texto.substring(first, linea)+"<br>";
      first = linea+1;
      linea += ancho
   }
   return temp;
}

stop()


Bueno a ver si alguín me echa una mano con esto.

Un saludo.

Por Aitcar

Claber

145 de clabLevel



Genero:Masculino  

msie
Citar            
MensajeEscrito el 03 Ene 2007 12:59 am
Haz la paginacion en la consulta sql y no del lado de cliente (Flash - Actionscript), asi tendrás mayor rendimiento en la aplicación.

Ejemplo de la consulta que debes hacer:

Código :

SELECT * FROM `Table` LIMIT cuantos OFFSET desde

donde:
cuantos: seria 5 en tu caso
desde: 0 primera pagina, 5 segunda pagina y asi sucesivamente

Lo recomendable es hacer una paginación por algun criterio de ordenamiento, asi que deberias definir tu campo para ordenar los resultados, por lo que la consulta quedaria asi:

Código :

SELECT * FROM `Table` ORDER BY `field` LIMIT cuantos OFFSET desde


saludos

Por Maikel

BOFH

5575 de clabLevel

22 tutoriales
5 articulos

Genero:Masculino   Team Cristalab

Claber de baja indefinida

firefox
Citar            
MensajeEscrito el 03 Ene 2007 01:26 am
Ok Maikel, voy a tratar..

Un saludo y gracias

Por Aitcar

Claber

145 de clabLevel



Genero:Masculino  

msie
Citar            
MensajeEscrito el 09 May 2008 03:52 pm
Me topé accidentalmente con este viejo POST ... pues solo para agradecer a Aitcar los créditos ;)

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox

 

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