Page 1 of 1

xBrowse: Process filtered rows only

Posted: Mon Jun 01, 2020 7:59 am
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

Re: xBrowse: Process filtered rows only

Posted: Thu Jun 11, 2020 8:28 am
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()
                         >

Re: xBrowse: Process filtered rows only

Posted: Thu Jun 11, 2020 9:44 am
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()
                         >