by nageswaragunupudi » Sun Dec 09, 2018 1:08 am
Please implement Autosort and Incremental seek with this code
- Code: Select all Expand view
REDEFINE XBROWSE oBrw id 111 of oDlg ;
COLUMNS "select", "receipt", "date", "name", "amount" ;
HEADERS 'Select', 'Receipt#', 'Date', 'Customer', 'Amount' ;
PICTURES nil, nil, nil, nil, '999,999,999.99' ;
DATASOURCE aFiledbf CELL LINES NOBORDER FASTEDIT AUTOSORT
WITH OBJECT oBrw
:Cargos := { "select", "receipt", "date", "name", "amount" }
:cSortOrders := { |oCol| HashArraySort( oCol ) }
:bSeek := { |c| HashArraySeek( oBrw, c ) }
// YOUR OTHER CODE HERE
END
Add these functions to your program
- Code: Select all Expand view
function HashArraySort( oCol )
local hSave := oCol:oBrw:aRow
local cKey := oCol:Cargo
local cOrder := If( oCol:cOrder == "A", "D", "A" )
if cOrder == "A"
if ValType( hSave[ cKey ] ) == "C"
ASort( oCol:oBrw:aArrayData, , , { |x,y| Upper( x[ cKey ] ) < Upper( y[ cKey ] ) } )
else
ASort( oCol:oBrw:aArrayData, , , { |x,y| x[ cKey ] < y[ cKey ] } )
endi
else
if ValType( hSave[ cKey ] ) == "C"
ASort( oCol:oBrw:aArrayData, , , { |x,y| Upper( x[ cKey ] ) > Upper( y[ cKey ] ) } )
else
ASort( oCol:oBrw:aArrayData, , , { |x,y| x[ cKey ] > y[ cKey ] } )
endi
endif
oCol:oBrw:nArrayAt := AScan( oCol:oBrw:aArrayData, { |h| h == hSave } )
return cOrder
function HashArraySeek( oBrw, cSeek )
local lFound := .f.
local nAt, oCol, cKey
nAt := AScan( oBrw:aCols, { |o| !Empty( o:cOrder ) } )
if nAt == 0
return .f.
endif
oCol := oBrw:aCols[ nAt ]
cKey := oCol:Cargo
cSeek := Upper( cSeek )
nAt := AScan( oBrw:aArrayData, { |h| Upper( cValToChar( h[ cKey ] ) ) = cSeek } )
if nAt == 0
return .f.
endif
oBrw:nArrayAt := nAt
return .t.
Regards
G. N. Rao.
Hyderabad, India