Page 1 of 1

Xbrowse - Select sort indexes

Posted: Wed May 12, 2021 12:40 am
by TimStone
I open a database object of all workorders. I set the initial index to only those which are still open ( active ). I use the account number field.

Now my clients want to have the ability to select another column. Here is the code for the initial display:

Code: Select all | Expand

   REDEFINE XBROWSE oLbxo  ;
    DATASOURCE ::oOrders  ;
    HEADERS " Done ", "Paid",  "Type", "W/O #", "Company", sLbl[4], sLbl[1], "Due Date", "Time",  " Started ", " Paid ", " Status " ;
    COLUMNS "ordnot", "Totals", "status", "wrkord", "ordcom","vehlic", "ordveh", "duedat", "duetim",  "wrkdat", "paydat", "CliUs1"  ;
    JUSTIFY  ,,2,2,,,2,2,2 ;
    ID 390 OF  oWdlg ;
    ON DBLCLICK ( ::oWorkOrder:FullEdit( ::oOrders, oWdlg ),  oLbxo:update(), oOrderList:LoadDisplayValues(  ), oWdlg:update()) ;
        ON CHANGE ( oOrderList:LoadDisplayValues( ), oWdlg:update() ) ;
        AUTOSORT UPDATE

   oLbxo:aCols[ 1 ]:SetCheck( { "CM1", "CM2" } )         // nil, .t. )
   oLbxo:aCols[ 2 ]:SetCheck( { "CM3","CM2"  } )         // nil, .t. )
   oLbxo:aCols[8]:bClrStd := {|| { ::CELL_COL1(  ), ::CELL_COL2( ) } }

    // Provide the header gradient
    oLbxo:bClrGrad := aPubGrad
    oLbxo:bClrSel = { || { 16777215, 15512898 } }
    // Set the styles
    oLbxo:nMarqueeStyle := MARQSTYLE_HIGHLROW
    oLbxo:nColDividerStyle := LINESTYLE_RAISED
    oLbxo:nRowDividerStyle := LINESTYLE_RAISED
    oLbxo:nHeadStrAligns  := AL_CENTER
    oLbxo:nStretchCol := STRETCHCOL_LAST

    // Use for incremental search on opened database
    oLbxo:bSeek := { |c| ::oOrders:Seek( Upper( c )) }
  oLbxo:lSeekBar := .t.
 


I have indexes created for the correct columns, but if I select on one of the others, it uses the index for the full database.

In this example, how can I use the lSeekBar with ONLY the proper indexes. Clearly this xBrowse is defined as a resource.

Thank you. It is slipping my mind at this point.

Re: Xbrowse - Select sort indexes

Posted: Wed May 12, 2021 9:40 pm
by TimStone
The answer to my original question is to use the SORT command. HOWEVER, here is the scenario.

When the screen opens, the index that shows only the open invoices is selected and applied to the xbrowse. I can use SORT and a list of indexes with the select bar turned on.

A user can press a Search button and select the option to look at all workorders based on client, or serviced item, or invoice number. I can turn off the seek bar so it doesn't display. However, if they select a header item anyway, then only the workorders open will display for that field. I need to make it so when an alternate search is applied, they can't select on the column name and change the index.

It may sound confusing ... but making lSeekBar .f. does not deactivate using a colun header to select an index ( order ).

Re: Xbrowse - Select sort indexes

Posted: Thu May 13, 2021 7:02 am
by nageswaragunupudi
1) If oBrw:lAutoSort is .T., user can switch the sort order by clicking on the header. If oBrw:lAutoSort is .F., then this feature is disabled. We can toggle this value during runtime.
making lSeekBar .f. does not deactivate using a colun header to select an index ( order ).

Set oBrw:lAutosort to .f., instead.

2)

Code: Select all | Expand


    oLbxo:bSeek := { |c| ::oOrders:Seek( Upper( c )) }
 

Please remove this line of code. XBrowse internally sets a default codeblock, which is better.

Re: Xbrowse - Select sort indexes

Posted: Thu May 13, 2021 6:04 pm
by TimStone
Thank you. That works perfectly.

Re: Xbrowse - Select sort indexes

Posted: Mon May 17, 2021 10:32 pm
by TimStone
If I might expand on this:

When constructing the xBrowse, I use: SORT ,,,ebaord, ebacli, ebavli ; which are the names of 3 indexes that are for some records in the database.

When running the program, I want a button click to change those to. ,,, ealord, eprcom, eprvli.
I have tried various options, but cannot get them to work. It is a browse called oLbx1

Looking at the include, I thought maybe. oLbx1:aSort := { ,,,ealord, eprcom, eprvli } might work, but aSort is not a DATA in the class.

Thanks for giving me some clarity on this.

Re: Xbrowse - Select sort indexes

Posted: Tue May 18, 2021 1:16 am
by nageswaragunupudi
We can change the sort index of a single column by:

Code: Select all | Expand


oCol:cSortOrder := "eprvli"
 


To change all the sort indexes of all columns:

Code: Select all | Expand


oLbx1:cSortOrders := { "", "", "","ealord", "eprcom", "eprvli" }
 

Re: Xbrowse - Select sort indexes

Posted: Tue May 18, 2021 5:43 pm
by TimStone
Thank you. cSortOrders was exactly what I was looking for.

Re: Xbrowse - Select sort indexes

Posted: Tue May 18, 2021 11:55 pm
by TimStone
Sorry to stay on this, but ....

I display an xbrowse with the one set of indexes. These are a subset of the full database. That works fine.

Now I want to use an alternate set of indexes which are built on the full database. With the first database displayed, a button will use the above command to change the indexes. This should automatically show the entire set of records. I update / refresh the xbrowse and the entire dialog, but it does not change the display.

Can you provide a quick sample of how to get it to switch ? Consider oLbx1 to be the browse, and oOrders to be the database object.

Thanks. If there is a sample in the distribution files, that would be great.

Re: Xbrowse - Select sort indexes

Posted: Wed May 19, 2021 3:47 pm
by nageswaragunupudi
Please build and run this sample in fwh\samples folder and let us know if this is what you are looking for,

Code: Select all | Expand

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   field CODE,NAME
   local oDbf, oDlg, oBrw, oBar, oCol

   FERASE( "STATES.CDX" )
   USE STATES EXCLUSIVE VIA "DBFCDX"
   INDEX ON UPPER(CODE) TAG CODE
   INDEX ON UPPER(NAME) TAG NAME ADDITIVE
   INDEX ON UPPER(CODE) TAG CODEX FOR CODE="W" ADDITIVE
   INDEX ON UPPER(NAME) TAG NAMEX FOR NAME="N" ADDITIVE
   CLOSE STATES

   oDbf  := TDatabase():Open( nil, "STATES", "DBFCDX", .t. )

   DEFINE DIALOG oDlg SIZE 360,450 PIXEL TRUEPIXEL
   DEFINE BUTTONBAR oBar OF oDlg SIZE 32,32 2007
   DEFINE BUTTON OF oBar PROMPT "1" CENTER ;
      ACTION ( oBrw:cSortOrders := { "CODE", "NAME" }, ;
               oCol := If( Empty( oBrw:oSortCol ), oBrw:SelectedCol(), oBrw:oSortCol ), ;
               oCol:SetOrder() )
   DEFINE BUTTON OF oBar PROMPT "2" CENTER ;
      ACTION ( oBrw:cSortOrders := { "CODEX", "NAMEX" }, ;
               oCol := If( Empty( oBrw:oSortCol ), oBrw:SelectedCol(), oBrw:oSortCol ), ;
               oCol:SetOrder() )

   @ 40,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oDbf ;
      COLUMNS "CODE","NAME" ;
      SORT "CODE", "NAME" ;
      AUTOSORT FOOTERS CELL LINES NOBORDER

   WITH OBJECT oBrw
      :RecSelShowRecNo()
      :bRecSelClick  := { || oBrw:SetOrderNatural() }
      :bOnSort := { || oBrw:GoTop(), oBrw:Refresh(), oBrw:SetFocus() }
      //
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

   oDbf:Close()

return nil
 

Re: Xbrowse - Select sort indexes

Posted: Wed May 19, 2021 5:30 pm
by TimStone
Nages,

Thank you. That got me on the right track and I now have my implementation. Rather than buttons, I used a Popup menu which is much cleaner, and my solution is now working great.

I appreciate your timely response and guidance.

Tim