Creating a CUSTOM Filter dialog for a column

SqlQuery is a new library that can be used to add much improved data browsing features to your applications. It is based on new features that are being added to eXpress++ build 267 and later - expected release August, 2019.
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4161
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Creating a CUSTOM Filter dialog for a column

#1 Post by rdonnay »

The DC_XbpColumnFiltered class has a method named GetFilter().

This method is invoked when a user right-clicks the heading of a browse column.
A dialog like the below captured screen will be displayed, allowing the user to select
a filter for the browse based on an entered value.
Filtered1.JPG
Filtered1.JPG (98.03 KiB) Viewed 6223 times
The programmer can create a custom GetFilter() method by overloading the method
in a custom class. In this example the custom class is LostAndFoundFiltered.

A dialog like the below captured screen will be displayed, allowing the user to select
a filter for the browse based on a drop-down list.
Filtered2.jpg
Filtered2.jpg (90.34 KiB) Viewed 6223 times
Sample code:

Code: Select all

DCBROWSECOL HEADER "Amount..." ;
    OBJECTVAR {|o| o:total } WIDTH 5 PARENT oBrowse PROTECT {||.t.} ;
    SUBCLASS 'DC_XbpColumnFiltered()' ;
    TOOLTIP "Fare Amount";
    SORT {|| ASort(aDtrRecs,,,{|a,b| Alltrim(Str(a:total)) < Alltrim(Str(b:total)) })}

DCBROWSECOL HEADER "Card#..." ;
    OBJECTVAR {|o| Pad(SubStr(Alltrim(o:cardnum),-4),4) } WIDTH 4 PARENT oBrowse PROTECT {||.t.} ;
    SUBCLASS 'LostAndFoundFiltered()' ;
    TOOLTIP "Last Four Digits Of Credit Card Number";
    SORT {|| ASort(aDtrRecs,,,{|a,b| a:last4 < b:last4 })}

DCBROWSECOL HEADER "Card Type..." ;
    OBJECTVAR {|o| o:cardtype} WIDTH 6 PARENT oBrowse PROTECT {||.t.} ;
    SUBCLASS 'LostAndFoundFiltered()' ;
    TOOLTIP "credit Card Type";
    SORT {|| ASort(aDtrRecs,,,{|a,b| a:cardtype < b:cardtype })}

DCBROWSECOL HEADER "Pick Up Location..." ;
     OBJECTVAR {|o| o:bgnloc} WIDTH 14 PARENT oBrowse PROTECT {||.t.} ;
     SUBCLASS 'DC_XbpColumnFiltered()' ;
     DATATOOLTIP {||.T.} ;
     TOOLTIP "Pick Up Location" ;
     SORT {|| ASort(aDtrRecs,,,{|a,b| a:bgnloc < b:bgnloc })}

* ---------------------

CLASS LostAndFoundFiltered FROM DC_XbpColumnFiltered

EXPORTED:

INLINE METHOD Init( oParent, oGetList )

::DC_XbpColumnFiltered:init( oParent, oGetList )
::heading:childlist()[1]:rbDown := {||::getFilter()}

RETURN self

* ----------

INLINE METHOD GetFilter()

LOCAL GetList[0], GetOptions, cSay, cPicture, lStatus, xDefaultVal, xValue

cSay := ::heading:childList()[1]:caption
cSay := StrTran(cSay, "...", "")

xValue := Eval(::dataLink)
IF Valtype(xValue) == 'C'
  xDefaultVal := Space(Len(xValue))
  ::filterVal := Pad(DC_XtoC(::filterVal),Len(xValue))
ELSEIF Valtype(xValue) == 'N'
  xDefaultVal := 0
  ::filterVal := Val(DC_XtoC(::filterVal))
  cPicture := '9999.99'
ENDIF

IF cSay = 'Card Type'

   ::filterVal := ArrPopUp( STRING  ::filterVal ;
                            ARR     {"All","Amex","Discover","MasterCard","Visa","Unknown","Cash"};
                            COLS    {{1,"Credit Card"}};
                            RETURN  1;
                            GETOBJECT BrowserHeaderArea(::parent,::columnPos);
                          )

  lStatus := .t.
ELSE

  @ 0,0 DCSAY cSay + " Filter";
      GET ::filterVal PICTURE cPicture;
      PROPER PROPOPTIONS {.F., Space(1) } ;
      SAYRIGHTBOTTOM ;
      POPUP {|a,oGet| ::filterVal := xDefaultVal};
      POPCAPTION "X" POPFONT '10.Arial' POPSTYLE DCGUI_POPUPSTYLE_IMBEDDED POPTABSTOP ;
      POPTOOLTIP "Clear Filter";
      SAYTOOLTIP "Enter " + cSay

   DCGETOPTIONS ;
      TABSTOP ;
      NOMINBUTTON ;
      NOMAXBUTTON ;
      NORESIZE

   DCREAD GUI OPTIONS GetOptions ADDBUTTONS FIT ENTEREXIT NOAUTORESTORE ;
     MODAL SETAPPWINDOW TO lStatus ;
     EVAL {|o| Pos_WinAtHeader(o, ::parent, ::columnPos) }

ENDIF

IF lStatus
  ::footerBlock := {||Chr(255)+Alltrim(DC_XtoC(::filterVal))}
  IF Empty(::filterVal)
    ::filterBlock := nil
  ELSEIF cSay = 'Med'
    IF AT("*", ::filterVal) > 0
      ::filterblock := {|o| AT(Alltrim(StrTran(::filterVal,"*", "")), Upper(o:mednum)) > 0 }
    ELSE
      ::filterBlock := {|o| Alltrim(o:mednum) = Alltrim(::filterVal)}
    ENDIF
  ELSEIF cSay = 'Hack'
    IF AT("*", ::filterVal) > 0
      ::filterblock := {|o| AT(Alltrim(StrTran(::filterVal,"*", "")), Upper(o:hack)) > 0 }
    ELSE
      ::filterBlock := {|o| Alltrim(o:hack) = Alltrim(::filterVal)}
    ENDIF
  ELSEIF cSay = 'Trip Id'
      ::filterBlock := {|o| Alltrim(o:servicenum) = Alltrim(::filterVal)}
  ELSEIF cSay = 'Pick Up'
    ::filterBlock := {|o| AT(Upper(Alltrim(::filterVal)), Upper(o:bgnloc)) > 0}
  ELSEIF cSay = 'Drop Off'
    ::filterBlock := {|o| AT(Upper(Alltrim(::filterVal)), Upper(o:endloc)) > 0}
  ELSEIF cSay = 'Card#'
    ::filterBlock := {|o| SubStr(Alltrim(o:cardnum), -4 ) = Alltrim(::filterVal) }
  ELSEIF cSay = 'Amount'
    ::filterBlock := {|o,nAmt| nAmt := Round(::filterVal, 2), o:total >= nAmt .AND. o:total <= Round(::filterVal, 2 )}
  ELSEIF cSay = 'Time'
    ::filterBlock := {|o,aHour| aHour := {Pad_Zero(Val(Substr(::filterVal,1,2))-1,2), Substr(::filterVal,1,2), ;
                                          Pad_Zero(Val(Substr(::filterVal,1,2))+1,2)}, ;
                                          SubStr(o:tol,1,2) $ aHour }
  ELSEIF cSay = 'Card Type'
     IF ::filterVal = "Cash"
       ::filterBlock := {|o| o:cardtype = Space(10)}
     ELSEIF ::filterVal = 'All'
       ::filterVal := ''
       ::filterblock := nil
     ELSE
       ::filterBlock := {|o| Alltrim(o:cardtype) = Alltrim(::filterVal)}
     ENDIF
  ENDIF
  ::parent:setFilter()
ENDIF

RETURN nil

ENDCLASS
The eXpress train is coming - and it has more cars.

Post Reply