Function Options(*DIRECT) Begin_Com Role(*EXTENDS #LRNG_FORM) * =============================================================== * LREX0004 : Using Tables - RDMLX MABI Table Examples * =============================================================== Define Field(#EmpName) Type(*char) Length(50) Define Field(#EmpAddr) Type(*char) Length(50) Define Field(#EmpImage) Type(*char) Length(50) Define Field(#EmpPhone) Type(*char) Length(20) Define Field(#EmpCntry) Type(*char) Length(50) Define Field(#uCount) Type(*dec) Length(5) Decimals(0) Def_List Name(#employees) Fields(#EmpName #EmpAddr #EmpImage #EmpPhone #EmpCntry) Counter(#uCount) Type(*WORKING) Entrys(*MAX) * Component that supplies test data Define_Com Class(#LREXCT04) Name(#TESTDATA) * The LRUDEMO component supplies utility methods to the LongRange Demo system and Example Formviews Define_Com Class(#lrudemo) Name(#DemoUtilities) Scope(*Application) * work fields Define_Com Class(#std_int) Name(#uEntry) Define_Com Class(#prim_alph) Name(#uEntryC) Define_Com Class(#prim_boln) Name(#uStatus) Define Field(#TableRow) Type(*string) Define_Com Class(#prim_alph) Name(#uText) Mthroutine Name(HandleRequest) Options(*REDEFINE) Define_Com Class(#prim_alph) Name(#CurrentRow) Define_Com Class(#prim_alph) Name(#TableRowCount) Define_Com Class(#prim_alph) Name(#ParamOut) Define_Com Class(#prim_boln) Name(#ResultOut) * ----------------------------------------- * Handle currently requested action * ----------------------------------------- * Always set the USING Element to /Form.Fields at the start #Com_Owner.Using Element('/Form.Fields') Case Of_Field(#COM_OWNER.RequestACTION) When (= VALUECHANGE) #COM_OWNER.IsNewForm := False When (= ROWCLICK) #COM_OWNER.IsNewForm := False * The current row ID should be from the one just selected * A Row can have multiple identifiers - this is identifier 1 #COM_OWNER.Get_Table Tablename(Table1) Currentrowid(#CurrentRow) Row_Id_N(1) #COM_OWNER.Set_Label Text('The row selected has ID ->' + #CurrentRow + '<- .') Layout_Col(1) Layout_Row(2) Color(Blue) * This uses Row identifier 2 #COM_OWNER.Get_Table Tablename(Table1) Currentrowid(#uEntryC) Row_Id_N(2) #Com_Owner.Get_Dropdown Name('Table1.Row%' + #uEntryC + '.DROPDOWN') Value(#uText) #COM_OWNER.Set_Label Text('The row selected has Gender: ' + #uText) Layout_Col(1) Layout_Row(3) Color(Blue) When (= SHOWPROG) #COM_OWNER.IsNewForm := False #COM_OWNER.Set_Label Name('/Form.Popover') Text('See Visual LANSA reusable part ' + #Com_Owner.Name) Color(Blue) #Com_Owner.Set_Form Show_Popover(TRUE) Otherwise /* Default */ If ('#uCount *eq 0') * Load up the list with test data #Com_Owner.LoadList Endif Endcase * -------------------------------------------------------------- * Format out the 'static' parts of the form view to be displayed * -------------------------------------------------------------- * Form #COM_OWNER.Set_Form Grid_Col_N(1) Grid_Col_Width(fill) #COM_OWNER.Set_Form Grid_Row_N(1) Grid_Row_Height(Fill) * Set an alternative title for small screen devices #DemoUtilities.SmallScreenTitle Title('Tables') * Basic Table set up #COM_OWNER.Set_Table Name(Table1) Border_Thickness(1) Border_Cornerradius(10) Onrowclick(ROWCLICK) Layout_Row(1) Layout_Col(1) Padding(0) #COM_OWNER.Set_Table Name(Table1) Col_N(1) Col_Name(Name) Col_Width(Fit) #COM_OWNER.Set_Table Name(Table1) Col_N(2) Col_Name(Phone) Col_Width(Fit) #COM_OWNER.Set_Table Name(Table1) Col_N(3) Col_Name(Address) Col_Width(fill) #COM_OWNER.Set_Table Name(Table1) Col_N(4) Col_Name(Date) Col_Width(Fit) #COM_OWNER.Set_Table Name(Table1) Col_N(5) Col_Name(Dropdown) Col_Width(fill) #COM_OWNER.Set_Table Name(Table1) Col_N(6) Col_Name(Bbutton) Col_Width(fit) * Set up Column Headers #COM_OWNER.Set_Label Name('Table1.Col%1.HEADER') Text('Name') Color(Blue) #COM_OWNER.Set_Label Name('Table1.Col%2.HEADER') Text('Phone') Color(Blue) #COM_OWNER.Set_Label Name('Table1.Col%3.HEADER') Text('Address') Color(Blue) #COM_OWNER.Set_Label Name('Table1.Col%4.HEADER') Text('Start Date') Color(Blue) #COM_OWNER.Set_Label Name('Table1.Col%5.HEADER') Text('Gender') Color(Blue) #COM_OWNER.Set_Label Name('Table1.Col%6.HEADER') Text('Select') Color(Blue) * Note, it is possible to set the row content elements by column by supplying values for the TableName and TableCol_N parameters. This may give gains in form view performance by not setting these properties on every row. * Set up start date in column 4 of Table1 (the properties that apply to all table rows) #COM_OWNER.Set_Date Tablename('Table1') Tablecol_N(4) Datetimevalueformat('ddMMyyyy') Datedisplayformat('dd/MM/yyyy') * Set up the Gender drop down in column 5 of Table1 (the properties that apply to all table rows) #COM_OWNER.Set_Dropdown Tablename('Table1') Tablecol_N(5) Onvaluechange(VALUECHANGE) #COM_OWNER.Set_Dropdown Tablename('Table1') Tablecol_N(5) Item_N(1) Item_Text('Female') Item_Value(F) #COM_OWNER.Set_Dropdown Tablename('Table1') Tablecol_N(5) Item_N(2) Item_Text('Male') Item_Value(M) #COM_OWNER.Set_Dropdown Tablename('Table1') Tablecol_N(5) Item_N(3) Item_Text('Not Specified') Item_Value(N) #COM_OWNER.Set_Button Tablename('Table1') Tablecol_N(6) Onclick(SELECT) #COM_OWNER.Set_Button Tablename('Table1') Tablecol_N(6) Border_Thickness(1) Border_Color(Red) Border_Cornerradius(5) Buttonfacecolor(Yellow) Text('Select') * Set up Column Contents #uEntry := 0 Selectlist Named(#employees) #uEntry := #uEntry + 1 Leave If(#uEntry > 20) #TableRow := 'Table1.Row%' + #uEntry.AsString #COM_OWNER.Set_Label Name(#TableRow + '.NAME') Text(#EmpName.RightTrim) #COM_OWNER.Set_Label Name(#TableRow + '.PHONE') Text(#EmpPhone.RightTrim) #COM_OWNER.Set_Label Name(#TableRow + '.ADDRESS') Text(#EmpAddr.RightTrim) * Only the values for the dropdown and date need to be set at the table-row level #COM_OWNER.Set_Date Name(#TableRow + '.Date') Value('28102005') #Com_Owner.Set_dropdown Name(#TableRow + '.DROPDOWN') Value(N) * The following commented code is replaced by the above that sets these properties by column number * #COM_OWNER.Set_Date Name(#TableRow + '.Date') Datetimevalueformat('ddMMyyyy') Datedisplayformat('dd/MM/yyyy') Value('28102005') * #COM_OWNER.Set_Dropdown Name(#TableRow + '.Dropdown') Value(M) Onvaluechange(VALUECHANGE) * #COM_OWNER.Set_Dropdown Name(#TableRow + '.Dropdown') Item_N(1) Item_Text('Female') Item_Value(F) * #COM_OWNER.Set_Dropdown Name(#TableRow + '.Dropdown') Item_N(2) Item_Text('Male') Item_Value(M) * #COM_OWNER.Set_Dropdown Name(#TableRow + '.Dropdown') Item_N(3) Item_Text('Not Specified') Item_Value(N) #COM_OWNER.Set_Table Name(Table1) Row_N(#uEntry) Row_Id((ID_ + #uEntry.AsString)) Row_Id_N(1) #COM_OWNER.Set_Table Name(Table1) Row_N(#uEntry) Row_Id(#uEntry.AsString) Row_Id_N(2) Endselect Endroutine Mthroutine Name(LoadList) * Prepare the test data #TESTDATA.uLoadData * Load the test data into a list Clr_List Named(#employees) #TESTDATA.GetFirstEmployee Uname(#EmpName) Uaddress(#EmpAddr) Ucountry(#EmpCntry) Uphone(#EmpPhone) Uentry(#uEntry) Ustatus(#uStatus) Uimage(#EmpImage) Dowhile Cond(#uStatus) Add_Entry To_List(#employees) #TESTDATA.GetNextEmployee Uname(#EmpName) Uaddress(#EmpAddr) Ucountry(#EmpCntry) Uphone(#EmpPhone) Uentry(#uEntry) Ustatus(#uStatus) Uimage(#EmpImage) Endwhile Endroutine End_Com