Page 1 of 1
sort an array on line Resolved!!
Posted: Thu Jan 10, 2019 9:41 am
by Silvio.Falconi
can I sort an array is on xbrowse ?
sample :
AaDd(atemp,{strzero(n,4),; //0001
SP->id,; // "O"
SP->DESC,; //"ooooooo"
SP->SETTORE,; //"A"
nGiorni,; //"1"
nPriceTemp,; //"10.00"
lIslock,; /7".t."
nIdListino } ) //"01"
I wish sort on idlistino
Re: sort an array on line
Posted: Thu Jan 10, 2019 12:35 pm
by nageswaragunupudi
Create xbrowse with AUTOSORT clause and click on the last header.
Re: sort an array on line
Posted: Thu Jan 10, 2019 5:16 pm
by Silvio.Falconi
Sorry but i wish sort on idlistino is not on x browse
Re: sort an array on line
Posted: Thu Jan 10, 2019 5:22 pm
by nageswaragunupudi
First sort the array
ASort( aTemp, , , { |x,y| x[ 8 ] < y[ 8 ] } )
Then build the XBrowse and do not use AUTOSORT.
Re: sort an array on line
Posted: Thu Jan 10, 2019 7:27 pm
by Silvio.Falconi
Sorry i make a mistake i have on array records having idlistino =1 and other =2 and i select with a combobox if 1 or 2 and i wish refrrsh the xbrowes showing only the idlistino =nselect
Re: sort an array on line
Posted: Fri Jan 11, 2019 4:53 am
by nageswaragunupudi
Code: Select all | Expand
#include "fivewin.ch"
function Main()
local oDlg, oFont, oBrw
local cFilter := "01"
local nFilterCol := 3
local aData := { ;
{ "one", "two", "01" }, ;
{ "three", "four", "01" }, ;
{ "five", "six", "02" }, ;
{ "seven", "eight", "02" }, ;
{ "nine", "ten", "02" } }
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 300,300 PIXEL TRUEPIXEL FONT oFont
@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE FilterArray( aData, nFilterCol, cFilter ) ;
COLUMNS 1,2 ;
CELL LINES NOBORDER
WITH OBJECT oBrw
:CreateFromCode()
END
@ 20,20 COMBOBOX cFilter ITEMS { "01", "02" } SIZE 100,400 PIXEL OF oDlg ;
ON CHANGE ( oBrw:aArrayData := FilterArray( aData, nFilterCol, cFilter ), ;
oBrw:GoTop(), oBrw:Refresh() )
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
static function FilterArray( aData, nFilterCol, cFilter )
local aFilter := {}
AEval( aData, { |a| If( a[ nFilterCol ] == cFilter, AAdd( aFilter, a ), nil ) } )
return aFilter
Re: sort an array on line
Posted: Fri Jan 11, 2019 9:10 am
by Silvio.Falconi
thanks .it was just what I was trying to do
Re: sort an array on line
Posted: Fri Jan 11, 2019 9:32 am
by Silvio.Falconi
Only I have a listini with two array (name,type)
type "Listino 1" ,"01"
Re: sort an array on line
Posted: Fri Jan 11, 2019 12:35 pm
by Silvio.Falconi
I correct with @ 36,75 COMBOBOX cFilter ITEMS ArrTranspose( aListini )[ 1] SIZE 100,400 PIXEL OF oDlgTariffe;
ON CHANGE ( oBrwBase:aArrayData := FilterArray( aData, nFilterCol, cFilter ), ;
oBrwBase:GoTop(), oBrwBase:Refresh() )

but Now i not see any record on when I select one items

the code
Code: Select all | Expand
#include "fivewin.ch"
REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO
function Tariffe()
local oDlg, oFont,oBold
local oBrwBase,oBrwTariffe
local aget[1]
local nFilterCol := 8
local aListini := Crea_Array_listini() //creation price_list
local aData := Crea_Base(aListini)
local cFilter := alistini[1][2]
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
DEFINE DIALOG oDlgTariffe SIZE 500,600;
PIXEL TRUEPIXEL RESIZABLE FONT oFont;
TITLE " Tariffe"
@ 10, 40 SAY oSay1 PROMPT "Tariffe Base" SIZE 400,24 PIXEL OF oDlgTariffe CENTER FONT oBold
@ 38,20 SAY "Listino :" SIZE 80,14 PIXEL OF oDlgTariffe
@ 70,20 XBROWSE oBrwBase SIZE -5,200 PIXEL OF oDlgTariffe ;
HEADERS "Elemento","Settore","Giorni","Costo", "Bloccato";
DATASOURCE FilterArray( aData, nFilterCol, cFilter ) ;
COLUMNS 3,4,5,6,7;
CELL LINES NOBORDER
WITH OBJECT oBrwBase
:CreateFromCode()
END
@ 36,75 COMBOBOX cFilter ITEMS ArrTranspose( aListini )[ 1] SIZE 100,400 PIXEL OF oDlgTariffe;
ON CHANGE ( oBrwBase:aArrayData := FilterArray( aData, nFilterCol, cFilter ), ;
oBrwBase:GoTop(), oBrwBase:Refresh() )
@ 550,260 BUTTON oBtnClose PROMPT "Conferma" SIZE 80,30 PIXEL OF oDlgTariffe;
ACTION NIL
@ 550,360 BUTTON oBtnOK PROMPT "Annulla" SIZE 80,30 PIXEL OF oDlgTariffe;
ACTION NIL
oDlgTariffe:bResized := <||
local oRect := oDlgTariffe:GetCliRect()
oBtnClose:nLeft := oRect:nRight - 220
oBtnClose:nTop := oRect:nBottom - 50
oBtnOK:nLeft := oRect:nRight - 120
oBtnOK:nTop := oRect:nBottom - 50
oBrwBase:refresh()
* oBrwTariffe:refresh()
RETURN nil
>
ACTIVATE DIALOG oDlgTariffe CENTERED
RELEASE FONT oFont, oBold
RETURN nil
//----------------------------------------------------------------//
static function FilterArray( aData, nFilterCol, cFilter )
local aFilter := {}
AEval( aData, { |a| If( a[ nFilterCol ] == cFilter, AAdd( aFilter, a ), nil ) } )
return aFilter
//----------------------------------------------------------------//
Function Crea_Array_listini()
Local alist_temp:={}
USE LISTINI ALIAS LI SHARE NEW VIA "DBFCDX"
INDEX ON NAME TAG "IDXLISTINI"
LI->(dbgotop())
DO While !LI->(eof())
AaDd(alist_temp,{ LI->NAME,LI->ID })
LI->(dbskip())
ENDDO
return alist_temp
//----------------------------------------------------------------//
Static Function Crea_Base(aListini)
Local atemp:={}
Local n := 1
Local nGiorni := 1
Local nPriceTemp:= 10
Local lIsLock := .t.
Local cId :=" "
Local cSector :=" "
USE SPIAGGIA ALIAS SP SHARE NEW VIA "DBFCDX"
INDEX ON id+settore TAG "IDXSETTORE"
SP->(ordSetFocus("IDXSETTORE")) //indicizzo su settori
SP->(dbgotop())
//Creo tariffe base secondo gli elementi che sono in archivio e per listino
Do while .not. SP->(eof())
IF !Empty(SP->SETTORE) .and. (sp->SETTORE!=cSector .or. sp->Id!=cId)
For k=1 to Len(aListini)
AaDd(atemp,{strzero(n,4),;
SP->id,;
SP->DESC,;
SP->SETTORE,;
nGiorni,;
nPriceTemp,;
lIslock,;
aListini[k][2] } )
n++
next
Endif
cSector := sp->SETTORE
cId := sp->Id
SP->(dbskip())
Enddo
return aTemp
Re: sort an array on line
Posted: Fri Jan 11, 2019 12:59 pm
by Silvio.Falconi
If I made (idea)
Code: Select all | Expand
static function FilterArray( aData, nFilterCol, cFilter, alistini )
local aFilter := {}
AEval( aData, { |a| If( a[ nFilterCol ] == Search_cod(cFilter,alistini) , AAdd( aFilter, a ), nil ) } )
return aFilter
Function search_cod(cFilter,alistini)
Local nAt := AScan( alistini, { |a| a[ 1 ] == cFilter } )
Local cCode:=""
If nAt>0
cCode:= alistini[nAt][2]
endif
return cCode
it run but on init I see the xbrowse empty ,,,any solution ?