Wilton Ergon Posted May 26, 2018 Posted May 26, 2018 i try unimenuitem1.visible :=false; unimenuitem2.visible :=false; UniTreeMenu.SOURCEMENU :=mainMenuItems; UniTreeMenu.Refresh; UniTreeMenu.Repaint; unigui 1.10.0.1458 unsuccessfully. Quote
Sherzod Posted May 29, 2018 Posted May 29, 2018 Hi, As an approximate solution for now procedure TMainForm.UniButton1Click(Sender: TObject); var I: Integer; _llist: string; begin with UniTreeMenu1 do begin SourceMenu.Items[0].Visible := False; _llist := ''; for I := 0 to SourceMenu.Items.Count-1 do if not SourceMenu.Items[I].Visible then if _llist='' then _llist := '"'+SourceMenu.Items[I].Caption+'"' else _llist := _llist + ',"' + SourceMenu.Items[I].Caption+'"'; if _llist<>'' then begin JSInterface.JSCall('getStore().clearFilter', []); JSInterface.JSCode(#1'.getStore().filterBy(function (record){ if (['+ _llist +'].indexOf(record.get("text"))>-1) return false; else return true;});'); end else JSInterface.JSCall('getStore().clearFilter', []); end; end; Best regards, Quote
Gabriel Posted June 27, 2018 Posted June 27, 2018 Hi, As an approximate solution for now procedure TMainForm.UniButton1Click(Sender: TObject); var I: Integer; _llist: string; begin with UniTreeMenu1 do begin SourceMenu.Items[0].Visible := False; _llist := ''; for I := 0 to SourceMenu.Items.Count-1 do if not SourceMenu.Items[I].Visible then if _llist='' then _llist := '"'+SourceMenu.Items[I].Caption+'"' else _llist := _llist + ',"' + SourceMenu.Items[I].Caption+'"'; if _llist<>'' then begin JSInterface.JSCall('getStore().clearFilter', []); JSInterface.JSCode(#1'.getStore().filterBy(function (record){ if (['+ _llist +'].indexOf(record.get("text"))>-1) return false; else return true;});'); end else JSInterface.JSCall('getStore().clearFilter', []); end; end; Best regards, Great. It only works when you are using TUniMenuItems as a SourceMenu? I'm creating the content of the menu at runtime and I can't make it work, Quote
Sherzod Posted March 5, 2019 Posted March 5, 2019 27 minutes ago, CoderU said: How hide subitems? Sample Tablet Application has menu Dashboard -> Save Dashboard -> Export Dashboard -> Print I mean runtime How hide Save menu or how hide all function if all function hide then hide parent menu Dashboard Hello, Ok I will check Quote
Sherzod Posted March 5, 2019 Posted March 5, 2019 And sorry, which edition and build of UniGUI are you using ?! Quote
Kattes Posted January 31, 2020 Posted January 31, 2020 Sorry but I also have problems using your solutions. I have the following uniTreeMenu structure: .. and want to hide menu items "Management" and its children for "simple" users. Therefor I am using the following code: procedure TuDashboardFrame.UniPanelLoginClick(Sender: TObject); var s : string; i : integer; begin with MainForm do begin for i := 0 to UniTreeMenu1.Items.Count-1 do begin s := UniTreeMenu1.Items[i].AttachedMenuItem.Caption; if pos(s, 'Database Management Customers')>0 then UniTreeMenu1.Items[i].AttachedMenuItem.Visible := false; end; UpdateTreeMenu(UniTreeMenu1); end; end; in combination with your slightly adapted solution: procedure UpdateTreeMenu (myMenu : TUniTreeMenu); var I: Integer; _llist: string; begin with myMenu do begin SourceMenu.Items[0].Visible := False; _llist := ''; for I := 0 to SourceMenu.Items.Count-1 do if not SourceMenu.Items[I].Visible then if _llist='' then _llist := '"'+SourceMenu.Items[I].Caption+'"' else _llist := _llist + ',"' + SourceMenu.Items[I].Caption+'"'; if _llist<>'' then begin JSInterface.JSCall('getStore().clearFilter', []); JSInterface.JSCode(#1'.getStore().filterBy(function (record){ if (['+ _llist +'].indexOf(record.get("text"))>-1) return false; else return true;});'); end else JSInterface.JSCall('getStore().clearFilter', []); end; end; Unfortunately this is not working Quote
Kattes Posted February 1, 2020 Posted February 1, 2020 Thank you Sherzod! I slightly modified the solution you sent me, which I also want to share with the community. procedure HideMenueItems(var MyTreeMenu: TUniTreeMenu; const sHide: string); var s,sH : string; i : integer; llist: string; begin llist := ''; sH := ','+sHide+','; for i := 0 to MyTreeMenu.Items.Count-1 do begin s := ','+MyTreeMenu.Items[i].AttachedMenuItem.Caption+','; if pos(s, sH)>0 then begin MyTreeMenu.Items[i].AttachedMenuItem.Visible := false; if llist='' then llist := '"'+MyTreeMenu.Items[I].AttachedMenuItem.Caption+'"' else llist := llist + ',"' + MyTreeMenu.Items[I].AttachedMenuItem.Caption+'"'; end; end; if llist<>'' then begin MyTreeMenu.JSInterface.JSAssign('_rtext', [MyTreeMenu.JSControl.JSArray(llist)]); MyTreeMenu.JSInterface.JSCode('var me='#1';'+ 'if(me._rtext) me.getStore().each(function(record) {'+ ' if (me._rtext.indexOf(record.get("text")) > -1) {'+ ' record.remove()'+ ' }'+ '});' ); end; end; procedure TMainForm.UniButtonHideClick(Sender: TObject); begin HideMenueItems(UniTreeMenu, 'Dashboard,Database,Management,Customers'); end; 1 Quote
Wilton Ergon Posted August 10, 2020 Author Posted August 10, 2020 On 2/1/2020 at 3:34 PM, Kattes said: Thank you Sherzod! I slightly modified the solution you sent me, which I also want to share with the community. procedure HideMenueItems(var MyTreeMenu: TUniTreeMenu; const sHide: string); var s,sH : string; i : integer; llist: string; begin llist := ''; sH := ','+sHide+','; for i := 0 to MyTreeMenu.Items.Count-1 do begin s := ','+MyTreeMenu.Items[i].AttachedMenuItem.Caption+','; if pos(s, sH)>0 then begin MyTreeMenu.Items[i].AttachedMenuItem.Visible := false; if llist='' then llist := '"'+MyTreeMenu.Items[I].AttachedMenuItem.Caption+'"' else llist := llist + ',"' + MyTreeMenu.Items[I].AttachedMenuItem.Caption+'"'; end; end; if llist<>'' then begin MyTreeMenu.JSInterface.JSAssign('_rtext', [MyTreeMenu.JSControl.JSArray(llist)]); MyTreeMenu.JSInterface.JSCode('var me='#1';'+ 'if(me._rtext) me.getStore().each(function(record) {'+ ' if (me._rtext.indexOf(record.get("text")) > -1) {'+ ' record.remove()'+ ' }'+ '});' ); end; end; procedure TMainForm.UniButtonHideClick(Sender: TObject); begin HideMenueItems(UniTreeMenu, 'Dashboard,Database,Management,Customers'); end; your example works perfectly, but it only removes the menu items, as I do to reassemble them and return the ones that were removed. if (me._rtext.indexOf(record.get("text")) > -1) {'+ ' record.remove()'+ ???? the example of friend Sherzod, applied only one filter to the menu items, this one does and removes the item, I need to recompose the items to return to the original state. Quote
Sherzod Posted August 11, 2020 Posted August 11, 2020 Hello, Are you using the latest UniGUI builds? Quote
emin Posted January 17, 2021 Posted January 17, 2021 I've used above script and it has worked. However a memory leak occurred. I have no idea how I fix the leak. I checked the script, it seemed Ok. Quote
Sherzod Posted January 18, 2021 Posted January 18, 2021 22 hours ago, emin said: I've used above script and it has worked. However a memory leak occurred. I have no idea how I fix the leak. I checked the script, it seemed Ok. Hello, Can you make a simple testcase to check? Quote
emin Posted January 18, 2021 Posted January 18, 2021 I added a test caseunitreemenutest.rar unitreemenutest.rar Quote
Sherzod Posted January 18, 2021 Posted January 18, 2021 10 minutes ago, emin said: I added a test caseunitreemenutest.rar Try this approach for now: ... if llist<>'' then begin //MyTreeMenu.JSInterface.JSAssign('_rtext', [MyTreeMenu.JSControl.JSArray(llist)]); MyTreeMenu.JSInterface.JSAssign('_rtext', [MyTreeMenu.JSInterface.JSStatement('[' + llist + ']')]); MyTreeMenu.JSInterface.JSCode('var me='#1';'+ 'if(me._rtext) me.getStore().each(function(record) {'+ ' if (me._rtext.indexOf(record.get("text")) > -1) {'+ ' record.remove()'+ ' }'+ '});' ); end; ... Quote
emin Posted January 18, 2021 Posted January 18, 2021 Hello Sherzod Memory leak warning disappeared when I used new script. Thanks your help, above and beyond your sincere help I think we need a documentation source to handle that kind of problem. To be honest it doesn't make sense for me why the memory leak has accured and why it's disappeared after replacing the script. I always try to understand logic instead of copy-paste script. But this time I couldn't Many thanks again 1 Quote
picyka Posted June 17, 2021 Posted June 17, 2021 I went back to addressing this item on my system, I still didn't have a solution, I was searching I found a code would it be possible to set no nodes visible? if not AMenu.Items[I].Visible then begin var lJs := #1'.getStore().getNodeById("' + AMenu.Items[I].Id.ToString + '");'; AMenu.JSInterface.JSCode(lJs); end; Quote
andyhill Posted June 19, 2021 Posted June 19, 2021 Sherzod, following on from above, how can we ADD Primary Items and ADD Child Items (not remove) ? Quote
风吹小机机 Posted June 19, 2021 Posted June 19, 2021 Yes, it can be cleared before creation, and then hidden or displayed after creation 1624084827640.mp4 1 Quote
picyka Posted June 19, 2021 Posted June 19, 2021 10 horas atrás, Andyhill disse: Sherzod, seguindo de cima, como podemos adicionar itens primários e adicionar itens infantis (não remover) ? I would like the same functionality we have in the demo http://prime.fmsoft.net/demo/desktop/mdemo.dll when searching the menu name Quote
andyhill Posted June 19, 2021 Posted June 19, 2021 "Yes, it can be cleared before creation, and then hidden or displayed after creation" I actually want a total new set of Menu Items (added at runtime when needed for each criteria), not a bloated Items List that we try to hide unwanted Items. Sherzod, how can we ADD MenuTree Primary Items and ADD associated Child Items (not remove) at runtime ? Quote
Frederick Posted June 6, 2024 Posted June 6, 2024 I have a TUniTreeMenu that has a TUniMenuItems as the source menu. When I attempt to hide a menu item with the following code, it does not work. procedure TMainForm.UniFormShow(Sender: TObject); begin mnu2.Visible:=False; hidemenuitems; end; procedure TMainForm.HideMenuItems; var I: Integer; _llist: string; begin with treMenu do begin SourceMenu.Items[0].Visible := False; _llist := ''; for I := 0 to SourceMenu.Items.Count-1 do if not SourceMenu.Items[I].Visible then if _llist='' then _llist := '"'+SourceMenu.Items[I].Caption+'"' else _llist := _llist + ',"' + SourceMenu.Items[I].Caption+'"'; if _llist<>'' then begin JSInterface.JSCall('getStore().clearFilter', []); JSInterface.JSCode(#1'.getStore().filterBy(function (record){ if (['+ _llist +'].indexOf(record.get("text"))>-1) return false; else return true;});'); end else JSInterface.JSCall('getStore().clearFilter', []); end; end; What am I missing? -- Frederick (UniGUI Complete - Professional Edition 1.95.0.1577) Quote
FXSystems Posted June 6, 2024 Posted June 6, 2024 Hi. Maybe this will help you solve your problem. I struggled with this for a long time, but the solution works: Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.