TDataGrid represents a data bound and updatable grid control.
To populate data into the datagrid, sets its {@link setDataSource DataSource}
to a tabular data source and call {@link dataBind()}.
Each row of data will be represented by an item in the {@link getItems Items}
collection of the datagrid.
An item can be at one of three states: browsing, selected and edit.
The state determines how the item will be displayed. For example, if an item
is in edit state, it may be displayed as a table row with input text boxes
if the columns are of type {@link TBoundColumn}; and if in browsing state,
they are displayed as static text.
To change the state of an item, set {@link setEditItemIndex EditItemIndex}
or {@link setSelectedItemIndex SelectedItemIndex} property.
Each datagrid item has a {@link TDataGridItem::getItemType type}
which tells the position and state of the item in the datalist. An item in the header
of the repeater is of type Header. A body item may be of either
Item, AlternatingItem, SelectedItem or EditItem, depending whether the item
index is odd or even, whether it is being selected or edited.
A datagrid is specified with a list of columns. Each column specifies how the corresponding
table column will be displayed. For example, the header/footer text of that column,
the cells in that column, and so on. The following column types are currently
provided by the framework,
- {@link TBoundColumn}, associated with a specific field in datasource and displays the corresponding data.
- {@link TEditCommandColumn}, displaying edit/update/cancel command buttons
- {@link TButtonColumn}, displaying generic command buttons that may be bound to specific field in datasource.
- {@link TDropDownListColumn}, displaying a dropdown list when the item is in edit state
- {@link THyperLinkColumn}, displaying a hyperlink that may be bound to specific field in datasource.
- {@link TCheckBoxColumn}, displaying a checkbox that may be bound to specific field in datasource.
- {@link TTemplateColumn}, displaying content based on templates.
There are three ways to specify columns for a datagrid.
- Automatically generated based on data source. By setting {@link setAutoGenerateColumns AutoGenerateColumns} to true, a list of columns will be automatically generated based on the schema of the data source. Each column corresponds to a column of the data.
- Specified in template. For example,
- Manually created in code. Columns can be manipulated via
the {@link setColumns Columns} property of the datagrid. For example,
$column=new TBoundColumn; $datagrid->Columns[]=$column;