Page 1 of 1

How to create columns dinamically

Posted: Thu Nov 03, 2016 2:33 am
by avescovi
Hi everyone,

I am trying to instantiate columns in a list (WEB) dinamically.
Some ideas?
Below a snippet of code (not compiling the line where I am trying to set the source) of my test.

Thank you

Andrea

Code: Select all


Define_Com Class(#PRIM_LIST) Name(#List1) Displayposition(1) Height(800) Left(0) Parent(#COM_OWNER) Tabposition(1) Top(0) Width(1200) Selectionstyle(All) Rowheight(22) Rowlines(False) Columnlines(False) Checkboxes(True)

Define_Com Class(#PRIM_KCOL<#PRIM_LIST.String #STD_NUM>) Name(#KCOL_column_list) Style(Collection)
Define_Com Class(#PRIM_KCOL<#STD_ALPHA #STD_NUM>) Name(#KCOL_column_value) Style(Collection)

Evtroutine Handling(#COM_OWNER.CreateInstance)
Set_Ref Com(#KCOL_column_list<1>) To(*CREATE_AS #PRIM_LIST.String)
Set_Ref Com(#KCOL_column_value<1>) To(*CREATE_AS #STD_ALPHA)

#KCOL_column_list<1>.Parent <= #List1
#KCOL_column_list<1>.DisplayPosition := 1
#KCOL_column_list<1>.Columncaptiontype := Caption
#KCOL_column_list<1>.ColumnCaption := 'Colonna 1'
#KCOL_column_list<1>.Source := #KCOL_column_value<1>
#KCOL_column_value<1> := 'test'
Add_Entry To_List(#List1)
* Create second column and so on...
Endroutine


Re: How to create columns dinamically

Posted: Thu Nov 03, 2016 9:49 am
by Stewart Marshall
Hi Andrea

The underlying list processing requires that the fields being used are known at compile time. This means that you can't apply a source to a column at run time and then hope to access it using the field value.

The sample below adds 4 columns to the list, indentifying each one by the name of a field. However, there is no link whatsoever to the variable of the same name, so the load routine is required to set specific column currentitem values to the appropriate variable value.

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Height(752) Width(1032) Theme(#SYS_THEME<2015Blue>) LayoutManager(#Layout1)
Define_Com Class(#PRIM_TBLO) Name(#Layout1)
Define_Com Class(#PRIM_TBLO.Row) Name(#LayoutRow1) DisplayPosition(1) Parent(#Layout1)
Define_Com Class(#PRIM_TBLO.Column) Name(#LayoutColumn1) DisplayPosition(1) Parent(#Layout1)
Define_Com Class(#PRIM_TBLO.Item) Name(#LayoutItem1) Column(#LayoutColumn1) Manage(#List) Parent(#Layout1) Row(#LayoutRow1)

Define_Com Class(#PRIM_LIST) Name(#List) DisplayPosition(1) Left(0) Parent(#COM_OWNER) TabPosition(1) Top(0) Width(1032) Height(752)

Define_Com Class(#Prim_kcol<#Prim_list.String #xDemoAlpha128>) Name(#Columns) Style(Collection)

Def_List Name(#Employees) Fields(#xEmployeeIdentification #xEmployeeTitle #xEmployeeSurname #xEmployeeGivenNames #xEmployeeDateofBirth #xEmployeeGender #xEmployeeStreet #xEmployeeCity #xEmployeeState #xEmployeePostalCode #xEmployeeCountry #xEmployeeHomeTelephone #xEmployeeBusinessTelephone #xEmployeeMobilePhone #xEmployeeSalary #xEmployeeStartDate #xEmployeeTerminationDate #xDepartmentCode #xEmployeeImageThumbnail) Counter(#Listcount) Type(*Working) Entrys(*Max)

Evtroutine Handling(#Com_owner.CreateInstance)

#Com_owner.AddColumn( xEmployeeIdentification )
#Com_owner.AddColumn( xEmployeeSurname )
#Com_owner.AddColumn( xEmployeeGivenNames )
#Com_owner.AddColumn( xEmployeeCity )

#Com_owner.Load

Endroutine

Mthroutine Name(AddColumn)
Define_Map For(*Input) Class(#Prim_Alph) Name(#FieldName)

#Columns<#FieldName> <= (*New #Prim_list.String)
#Columns<#FieldName>.Parent <= #List
#Columns<#FieldName>.ColumnCaption := #FieldName
#Columns<#FieldName>.ColumnCaptionType := Caption
#Columns<#FieldName>.DisplayPosition := #Columns.ItemCount

Endroutine

Mthroutine Name(Load)

Define_Com Class(#xDemoWebDataServices.GetEmployees) Name(#GetEmployees)

#GetEmployees.ExecuteAsync( #Employees )

Evtroutine Handling(#GetEmployees.Completed)

Selectlist Named(#Employees)

Add_Entry To_List(#List)

#Columns<xEmployeeIdentification>.CurrentItem.Value := #xEmployeeIdentification
#Columns<xEmployeeSurname>.CurrentItem.Value := #xEmployeeSurname
#Columns<xEmployeeGivenNames>.CurrentItem.Value := #xEmployeeGivenNames
#Columns<xEmployeeCity>.CurrentItem.Value := #xEmployeeCity

Endselect

Endroutine

Endroutine

End_Com
Regards