I want to add #PRIM_MD.TabItem items to #PRIM_MD.Tab at run time. I don't know how many I will need.
I've tried the code below and, although it executes, I don't see any tabs.
I can't find any examples.
Anyone got any clues.
Evtroutine Handling(#Com_owner.Initialize)
Define_Com Class(#PRIM_MD.TabItem) Name(#newtab) Reference(*DYNAMIC)
#SYS_WEB.Console.Log( 'Init' )
Begin_Loop Using(#x) To(10)
#SYS_WEB.Console.Log( #x.AsString )
#newtab <= *New #PRIM_MD.TabItem
#newtab.Parent <= #tab
#newtab.Caption := #x.AsString
#newtab.DisplayPosition := #x
#newtab.Tabposition := #x
#newtab.Height := 50
#newtab.Width := 100
#newtab.Visible := True
End_Loop
#SYS_WEB.Console.Log( 'End Init' )
Endroutine
End_Com
Dynamic #PRIM_MD.Tab
Re: Dynamic #PRIM_MD.Tab
Use a collection of tab_items...
Code: Select all
Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>)
Define_Com Class(#PRIM_MD.Tab) Name(#Tab) DisplayPosition(1) Height(50) Left(36) Parent(#COM_OWNER) TabPosition(1) ThemeDrawStyle('DarkTitle') Top(68) Width(500)
* Define_Com Class(#PRIM_MD.TabItem) Name(#TabItem) Caption('ITEM 1') DisplayPosition(1) Height(50) Left(0) Parent(#Tab) TabPosition(1) TabStop(True) Top(0)
* Define_Com Class(#PRIM_MD.TabItem) Name(#TabItem1) Caption('ITEM 2') DisplayPosition(2) Height(50) Left(100) Parent(#Tab) TabPosition(2) TabStop(True) Top(0)
Define Field(#x) Type(*Dec) Length(3) Decimals(0)
Define_Com Class(#PRIM_KCOL<#PRIM_MD.TabItem #STD_NUM>) Name(#TabSheets) Reference(*Dynamic) Style(Collection)
Evtroutine Handling(#Com_owner.Initialize)
If_Ref Com(#TabSheets) Is_Not(*null)
Set_Ref Com(#TabSheets) To(*null)
Endif
Set_Ref Com(#TabSheets) To(*Create_as #PRIM_KCOL<#PRIM_MD.TabItem #STD_NUM>)
Begin_Loop Using(#x) To(10)
Set_Ref Com(#TabSheets<#x>) To(*CREATE_AS #PRIM_MD.TabItem)
Set Com(#TabSheets<#x>) Width(50) DisplayPosition(#x) TabPosition(#x) Parent(#Tab) Caption(#x.AsString) Height(50) Visible(True) Left(#x * 50)
End_Loop
Endroutine
End_Com
-
jimwatterson
- Posts: 56
- Joined: Thu Jul 09, 2020 8:31 am
Re: Dynamic #PRIM_MD.Tab
Thanks Dino, as usual worked out of the box!
I've added this routine to tell me what has been clicked and it works
Evtroutine Handling(#Tab.Click) Origin(#origin)
Define_Com Class(#PRIM_MD.TabItem) Name(#t) Reference(*DYNAMIC)
#t <= (#origin *As #PRIM_MD.TabItem)
#SYS_WEB.Console.Log( ('selected=' + #t.Caption) )
Endroutine
What I need to do now is select the first item programatically on load but there doesn't seem to be an active item property on the tab or tabitem?
I've added this routine to tell me what has been clicked and it works
Evtroutine Handling(#Tab.Click) Origin(#origin)
Define_Com Class(#PRIM_MD.TabItem) Name(#t) Reference(*DYNAMIC)
#t <= (#origin *As #PRIM_MD.TabItem)
#SYS_WEB.Console.Log( ('selected=' + #t.Caption) )
Endroutine
What I need to do now is select the first item programatically on load but there doesn't seem to be an active item property on the tab or tabitem?
Re: Dynamic #PRIM_MD.Tab
jim,
for a collection:
I would use the ComponentTag (eg #TabItems<1>.ComponentTag ) to set an identifier for the Tab
After creating your TabItems you can do:
to 'select' a tab -- you simply need it assigned a VISIBLE VIEW (so if they dont have one, then use #com_self or #com_owner, but make sure to set all the other tabs to *Null.
for a collection:
Code: Select all
*Global collection for the VIEW -- do not define inside a method...
define_com class(#prim_lcol<#prim_md.tabItem>) name(#TabItems)
After creating your TabItems you can do:
Code: Select all
Evtroutine Handling(#TabItems<>.Click) com_sender(#Sender)
* #Sender will be the individual tab item...
case of (#Sender.ComponentTag)
* do what is require for individual tab.
endcase
#com_self.SetActiveTab(#Sender.ComponentTag
endroutine
Code: Select all
mthroutine Named(SetActiveTab)
define_map for(*input) class(#prim_alph) name(#TabIdentifier)
for each(#Entry) in(#TabItems)
#Entry.View <= *Null
if (#Entry.ComponentTag = #TabIdentifier)
#Entry.View <= #com_self
endif
endfor
endroutine