xBrowse: Process filtered rows only

Post Reply
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

xBrowse: Process filtered rows only

Post by hua »

Hi Rao,
I have a 'Select All' checkbox. Right now it has this code attach to it

Code: Select all

      oCbxAll:bChange := <||
                             aeval(oBrw:aArrayData, {|h_| h_["select"] := lAll})
                             oBrw:refresh()
                         >
 
But it has been pointed out to me this logic is not accurate if someone did filtering prior to checking it as it will traverse the whole array, not just filtered ones
Image

As shown in the screen above which is displaying an array of hashes, when user clicks 'Select All' it is expected only the two visible rows should have the select flag toggled.
How should I code oCbxAll:bChange so it updates only filtered rows?

TIA
Last edited by hua on Fri Jun 12, 2020 3:07 am, edited 1 time in total.
FWH 11.08/FWH 19.03
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Re: xBrowse: Process filtered rows only

Post by hua »

I got an idea to do it this way. But seems to be caught in an infinite loop

Code: Select all

    redefine checkbox oCbxAll var lAll id 109 of oDlg
      oCbxAll:bChange := <||
                              local hState := {=>}
                              hState["BookMark  "] := oBrw:BookMark
                              hState["nRowSel   "] := oBrw:nRowSel
                              hState["nColSel   "] := oBrw:nColSel
                              hState["nColOffset"] := oBrw:nColOffset
                              oBrw:gotop()
                              do while !oBrw:eof()
                                 h_ := oBrw:aRow()
                                 h_["select"] := lAll
                                 oBrw:goDown()
                              enddo
                              oBrw:BookMark   := hState["BookMark  "]
                              oBrw:nRowSel    := hState["nRowSel   "]
                              oBrw:nColSel    := hState["nColSel   "]
                              oBrw:nColOffset := hState["nColOffset"]
                              oBrw:refresh()
                         >
FWH 11.08/FWH 19.03
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Re: xBrowse: Process filtered rows only

Post by hua »

Ok. This version seems to work

Code: Select all

      oCbxAll:bChange := <||
                              local hState := {=>}
                              hState["BookMark  "] := oBrw:BookMark
                              oBrw:gotop()
                              REPEAT
                                 h_ := oBrw:aRow()
                                 h_["select"] := lAll
                              UNTIL oBrw:Skip( 1 ) != 1

                              oBrw:BookMark   := hState["BookMark  "]
                              oBrw:refresh()
                         >
FWH 11.08/FWH 19.03
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
Post Reply