Creates an HTML table from a cursor and returns the HTML as a string.

This implementation creates an HTML table grid layout that uses a CSS styling to control rendering and formatting for the table and columns. Automatic mode renders a table from existing data using meta data, or you can manually configure columns to add to the display.

The default styling uses styles in westwind.css: .gridheader, .gridalternate,.blackborder, all of which can be overridden via properties or by adding these styles to your own style sheets and changing the display features.


Return Value

Html of the rendered table


The name of the cursor or alias that is to be rendered.

An HtmlDataGridConfig object instance that configures this DataGrid instance.

Optional ID for the table created


The following produces a simple non-paged table that simply uses fieldnames for column headers.

lcHtml = HtmlDataGrid("TCustomers")

The following produces simple table that has a couple of simple properties set such as paging enabled and an explicit Width set:

loConfig = CREATEOBJECT("HtmlDataGridConfig")
loConfig.Width = "800px"
loConfig.Id = "tblCustomers"
loConfig.PageSize = 10

lcHtml = HtmlDataGrid("TCustomers",loConfig)

The following is a more sophisticated example that uses more extensive configuration and columns:

* **Create the configuration helper object to set 
* **rendering options and each individual column to render
loConfig = CREATEOBJECT("HtmlDataGridConfig")

* **Main configuration options
loConfig.Width = "900px"
loConfig.CssClass = "blackborder"
loConfig.Style = "margin-top: 30px;"
loConfig.DataKeyField = "Pk"

* **Paging configuration
loConfig.PageSize = 10
*loConfig.PageBaseLink = "HtmlDataGrid.wwd?" 

* **Embedding a link with an expression - an HREF link in this case
loColumn = CREATEOBJECT("HtmlDataGridColumn")
loColumn.Expression = [HtmlLink("customer.wwd?id=" + TRANSFORM(,TCustomers.Company)]
loColumn.HeaderText = "Company"
loColumn.SortExpression = "UPPER(Company)"

* **Embedding a plain and simple field  - using easier loConfig.AddColumn() syntax
loColumn = loConfig.AddColumn("TCustomers.CareOf","Name)
loColumn.SortExpression = "Upper(Careof)"

* **Apply Fox formatting
loColumn = loConfig.AddColumn("BillRate","Rate","N")
loColumn.Format = "$$$,$$$.99"
loColumn.ItemAttributeString = [ style="text-align: right" ]

lcHtml = HtmlDataGrid("TCustomers",loConfig)

See also:

Class wwHtmlHelpers | Class HtmlDataGridConfig | Class HtmlDataGridColumn | Code Example for creating a fully custom Data Grid

© West Wind Technologies, 1996-2019 • Updated: 01/17/19
Comment or report problem with topic