Quoi, tu ne connais pas PB ? Va falloir parcourir tout le forum alors !

Le forum (ô combien francophone) des utilisateurs de Powerbuilder.

Recherche rapide

Annonce

Certaines rubriques, dont des cours, sont uniquement visibles par les membres du forum ^^.
Dans la rubrique Liens & Références, vous avez accès à un sommaire de téléchargement, profitez-en !
Il existe maintenant un nouveau TOPIC "Votre CV en Ligne" accessible uniquement par demande.

#1 07-09-2006 21:46:03

pick ouic  
La bourse ou la vie ^^
Award: gearotter
Lieu: Massy-Verrières
Date d'inscription: 29-05-2006
Messages: 4658
Pépites: 942
Banque: 2,147,483,647
Site web

[SOURCE] Trier la colonne d'une liste datawindow

ordre croissant
http://img354.imageshack.us/img354/9479/tri1it4.png

ordre decroissant
http://img482.imageshack.us/img482/7463/tri2gx6.png


importer d'abord cette fonction "f_sort_triangle"

Code: pb

$PBExportHeader$f_sort_triangle.srf
$PBExportComments$permet de faire le tri
global type f_sort_triangle from function_object
end type

forward prototypes
global subroutine f_sort_triangle (string as_column, datawindow adw_dw, string as_sort)
end prototypes

global subroutine f_sort_triangle (string as_column, datawindow adw_dw, string as_sort);/********************************************************************
Create_SortKey
           
<DESC>  Create a sort key image for the given column.</DESC>
                            
<ACCESS>Protected

 <ARGS>  as_Column: Column Name to Create for.
         as_sort: Sort Sequence A/D.</ARGS>

 <USAGE> this.Create_SortKey( 'column1', 'A' )</USAGE>
                            
********************************************************************/
Long ll_X1, ll_Y1, ll_X2, ll_Y2, ll_X3, ll_x4, ll_Y3, ll_Y4
String ls_Mod
datawindow ldw_dw
// Get the datawindow control for the service
ldw_DW = adw_dw

ldw_DW.SetRedraw( FALSE )

ll_X1 = Long( ldw_DW.Describe( as_Column + '_t.X' ) ) + 5
ll_Y1 = Long( ldw_DW.Describe( as_Column + '_t.Y' ) ) + 3

ls_Mod = 'destroy sort_ln1 destroy sort_ln2 destroy sort_ln3'
ldw_DW.Modify( ls_Mod )

ll_X2 = PixelsToUnits( &
                            UnitsToPixels( ll_X1, XUnitsToPixels! ) + 4, XPixelsToUnits! )
ll_X3 = PixelsToUnits( &
                            UnitsToPixels( ll_X1, XUnitsToPixels! ) + 3, XPixelsToUnits! )
ll_X4 = PixelsToUnits( &
                            UnitsToPixels( ll_X1, XUnitsToPixels! ) + 8, XPixelsToUnits! )
ll_Y2 = PixelsToUnits( &
                            UnitsToPixels( ll_Y1, YUnitsToPixels! ) + 4, YPixelsToUnits! )
ll_Y3 = PixelsToUnits( &
                            UnitsToPixels( ll_Y1, YUnitsToPixels! ) + 5, YPixelsToUnits! )
ll_Y4 = PixelsToUnits( &
                            UnitsToPixels( ll_Y1, YUnitsToPixels! ) - 1, YPixelsToUnits! )

// If the sort sequence is ascending or decending
IF as_Sort = 'A' THEN
   ls_Mod = 'create line(band=foreground x1="' + String( ll_X1 ) &
      + '" y1="' + string( ll_Y1 ) &
      + '" x2="' + String( ll_X4 ) + '" y2="' &
      + String( ll_Y1 ) + '" pen.style="0" pen.width="5" ' &
      + 'pen.color="33554432"  background.mode="2" ' &
      + 'background.color="16777215" name=sort_ln1 )'
                            
   ls_Mod += ' create line(band=foreground x1="' + String( ll_X1 ) &
      + '" y1="' + string( ll_Y1 ) &
      + '" x2="' + String( ll_X2 ) + '" y2="' &
      + String( ll_Y2 ) + '" pen.style="0" pen.width="5" ' &
      + 'pen.color="33554432"  background.mode="2" ' &
      + 'background.color="16777215" name=sort_ln2 )'
                            
   ls_Mod += ' create line(band=foreground x1="' + String( ll_X4 ) &
          + '" y1="' + string( ll_Y1 ) &
          + '" x2="' + String( ll_X3 ) + '" y2="' &
          + String( ll_Y3 ) + '" pen.style="0" pen.width="5" ' &
          + 'pen.color="1089522856"  background.mode="2" ' &
          + 'background.color="16777215" name=sort_ln3 )'

ELSE
   ls_Mod = 'create line(band=foreground x1="' + String( ll_X1 ) &
          + '" y1="' + string( ll_Y2 ) &
          + '" x2="' + String( ll_X4 ) + '" y2="' + String( ll_Y2 ) &
          + '" pen.style="0" pen.width="5" ' &
          + 'pen.color="1089522856"  background.mode="2" ' &
          + 'background.color="16777215" name=sort_ln1 )'
                            
   ls_Mod += ' create line(band=foreground x1="' + String( ll_X1 ) &
          + '" y1="' + string( ll_Y2 ) &
          + '" x2="' + String( ll_X2 ) + '" y2="' + String( ll_Y1 ) &
          + '" pen.style="0" pen.width="5" ' &
          + 'pen.color="33554432"  background.mode="2" ' &
          + 'background.color="16777215" name=sort_ln2 )'
                            
   ls_Mod += ' create line(band=foreground x1="' + String( ll_X4 ) &
          + '" y1="' + string( ll_Y2 ) &
          + '" x2="' + String( ll_X3 ) + '" y2="' &
          + String( ll_Y4 ) + '" pen.style="0" pen.width="5" ' &
          + 'pen.color="1089522856"  background.mode="2" ' &
          + 'background.color="16777215" name=sort_ln3 )'
END IF

// Create the triangle
ldw_DW.Modify( ls_Mod )
ldw_DW.SetRedraw( TRUE )
end subroutine

ensuite celle-ci "f_sortdw" qui appelle "f_sort_triangle"

Code: pb

$PBExportHeader$f_sortdw.srf
$PBExportComments$permet de faire le tri d'une colonne de la dw
global type f_sortdw from function_object
end type

forward prototypes
global function integer f_sortdw (datawindow adw_dw, string as_colonne, string as_data, string as_dataold, boolean ab_couleur, ref string as_newdata, ref string as_newdataold)
end prototypes

global function integer f_sortdw (datawindow adw_dw, string as_colonne, string as_data, string as_dataold, boolean ab_couleur, ref string as_newdata, ref string as_newdataold);/*********************************************************************************************/
/* Nom    :   f_sortdw                                                */
/* But    :                                                       */
/* Arguments:                                                       */
/*  Appel    :                                                        */
/* Remarques:                                                        */
/* Histo    :   SKA                                                  */
/*********************************************************************************************/

string   ls_col
long     ll_pos, ll_len
long    ll_ret

ll_ret  = 0
ls_col   = as_colonne
ll_len   = len(ls_col)
ll_pos   = pos(ls_col, "_t",ll_len - 3)

// on repere ici s'il s'agit ou non d'une colonne portant le meme nom de colonne et se terminant par _t
// si oui, on effetuera le tri et on retourne 1
if ll_pos > 0 then
  ls_col = left(ls_col,ll_pos - 1)
  if as_data = as_colonne then
      f_sort_triangle(ls_col,adw_dw,"D")
      ls_col     = ls_col + " D"
      as_dataold   = as_data
      as_data     = ""
      
      if ab_couleur then
        adw_dw.modify(as_colonne + ".color = 16711680")
      end if  
  else
      f_sort_triangle(ls_col,adw_dw,"A")
      adw_dw.modify(as_dataold + ".color = 8388608")
      ls_col     = ls_col + " A"
      as_data     = as_colonne
      as_dataold   = as_data
      
      if ab_couleur then
        adw_dw.modify(as_colonne + ".color = 255")
      end if
  end if
  adw_dw.setsort(ls_col)
  adw_dw.Sort()
  ll_ret = 1
end if    
    
as_newdata     = as_data
as_newdataold   = as_dataold

return ll_ret
end function

ATTENTION, Renommer bien les entetes de vos colonnes, il faut qu'elles soient identiques, et se terminant par _t

maintenant, depuis votre fenetre,
declarer 2 variables d'instances pour la datawindow concernée.

Code: pb

string is_data, is_data_old

et mettez ce script sur l'evenement DOUBLECLICKED de la datawindow utilisée

Code: pb

f_sortdw(this,dwo.name,is_data,is_data_old,true,is_data,is_data_old)

et le tour est joué !!!!!


Connaitre son ignorance est une grande part de la connaissance.
http://animegifs.free.fr/anime/mazinger/mazinger.gif

Hors ligne

 

#2 16-04-2012 14:56:26

Ben53  
Membre Geek
Date d'inscription: 18-02-2010
Messages: 46
Pépites: 184
Banque: 0

Re: [SOURCE] Trier la colonne d'une liste datawindow

Merci beaucoup pour le script, à la fois très pratique et instructif !

Hors ligne

 

#3 17-04-2012 12:16:13

Geo  
Membre completement Geek
Lieu: Binche
Date d'inscription: 15-12-2008
Messages: 119
Pépites: 378
Banque: 0

Re: [SOURCE] Trier la colonne d'une liste datawindow

Merci pour ce script, on l'a implanté dans notre framework de développement qui permettait le tri mais sans affichage d'indicateur.
Visuellement c'est un plus incontestable


Rien ne sert de courir, il faut partir à point .

Hors ligne

 

Pied de page des forums

Propulsé par FluxBB 1.2.22