SqlGrid

model.SqlGrid(sql)
Parameters:

sql (str) – SQL query to execute and display as a grid

Returns:

HTML string containing a formatted table with the query results

Return type:

str

Executes the provided SQL query and returns the results as an HTML table with responsive styling. The function automatically handles formatting of different data types:

  • Money and decimal values are right-aligned and formatted as currency

  • Percentage values (columns with names containing “pct” or “percent”) are formatted with % symbol

  • Date/time values are appropriately formatted

  • Integer values for IDs and years maintain standard formatting

  • Other numeric values are right-aligned with thousands separators

The function also provides special handling for certain column names:

  • “peopleid” and “spouseid” columns are rendered as links to the corresponding Person pages

  • “organizationid” and columns ending with “orgid” are rendered as links to the Organization pages

  • Columns named “pagebreak” are used for special formatting but not displayed

  • Columns named “linkfornext” can be used to make the next column’s value a clickable link

If the SQL query contains the parameter @BlueToolbarTagId, the function will automatically populate it with the ID of a temporary tag containing the people from the current BlueToolbar selection (if available).

Example:

sql = '''
    SELECT TOP 10
        p.PeopleId,
        p.Name,
        p.DOB,
        p.Age,
        o.OrganizationId,
        o.OrganizationName
    FROM People p
    JOIN OrganizationMembers om ON om.PeopleId = p.PeopleId
    JOIN Organizations o ON o.OrganizationId = om.OrganizationId
    WHERE p.Age > 18
    ORDER BY p.Name
'''
print model.SqlGrid(sql)


Latest Update

3/28/2025

Added documentation for SqlGrid function.