Suppressing Blank Fields in an Address
Description
This example shows how to hide blank fields when displaying an address.
Create a read-only tabular grid based on the Customer table of the AlphaSports sample database.
Display the Grid > Fields page.
Move the "Firstname", "Lastname", "Phone", "Bill_Address_1", "Bill_Address_2", "Bill_City", "Bill_State_Region", "Bill_Postal_Code", and "Bill_Country" fields from the Available Fields list to the Selected Fields list.
Select the "Firstname" field in the Selected Fields list and set its Column Properties > Hide column property to "True".
Select the "Lastname" field in the Selected Fields list:
function LASTNAME_render as C (data as P, args as P, PageVars as P) 'do not delete this line with PageVars 'do not delete this lineon error goto LASTNAME_XbasicError 'do not delete this line LASTNAME_render = alltrim(data.Firstname) + " " + Alltrim(Data.LASTNAME) end 'do not delete this line LASTNAME_XbasicError: 'do not delete this line LASTNAME_render = "Error in custom control Xbasic: " + error_text_get()'do not delete this line end with 'do not delete this line end function 'do not delete this line
Set its Display Settings > Control type property to "Custom".
Set its Column Properties> Control heading property to "Name".
Set its Column Properties> Heading in-line style property to "text-align: left;".
Click the '...' button in the Custom Control Properties > Definition property to display the Define Xbasic for Custom Control dialog.
Modify the code as follows and click OK.
Select the "Phone" field in the Selected Fields list and set its Column Properties> Heading in-line style property to "text-align: left;".
Select the "Bill_Address_1" field in the Selected Fields list:
Set its Display Settings > Control type property to "Custom".
Set its Column Properties> Control heading property to "Address".
Set its Column Properties> Heading in-line style property to "text-align: left;".
Click the '...' button in the Custom Control Properties > Definition property to display the Define Xbasic for Custom Control dialog.
Modify the code as follows and click OK.
function BILL_ADDRESS_1_render as C (data as P, args as P, PageVars as P) 'do not delete this line with PageVars 'do not delete this line on error goto BILL_ADDRESS_1_XbasicError 'do not delete this line BILL_ADDRESS_1_render = remove_blank_linesData.BILL_ADDRESS_1) + crlf()+ alltrim(Data.BILL_ADDRESS_2) + crlf()+ alltrim(Data.BILL_CITY) + ", " + alltrim(Data.BILL_STATE_REGION) + " " + alltrim(Data.BILL_POSTAL_CODE) + crlf()+ alltrim(Data.BILL_country? BILL_ADDRESS_1_render = stritran(BILL_ADDRESS_1_render, crlf(), "<br>") end 'do not delete this line BILL_ADDRESS_1_XbasicError: 'do not delete this line BILL_ADDRESS_1_render = "Error in custom control Xbasic: " + error_text_get()'do not delete this line end with 'do not delete this line end function 'do not delete this line
Select the "Bill_Address_2", "Bill_City", "Bill_State_Region", "Bill_Postal_Code", and "Bill_Country" fields in the Selected Fields list and set their Column Properties > Hide column property to "True".
Display the Grid > Properties page.
Set the Layout Options > Style name to "Arizona".
Set the Layout Options > Rows of data to 5.
Set the Shading and Dividers > Alternate row shading to "True".
Set the Customization > Row separator HTML to
" <tr><td class="{a5_style}SeparatorTD" colspan="{a5_colspan}" style="padding: 0px;" ></td></tr> "
This creates a white band that separates the rows.Save your work and click the Browser button. You should see something like this.