Cells and CellManagers
Cells and Cell Managers
Overview
Each cell in the grid is a composite visual object composed of nested visual elements, adhering to the Fmx.TControl model. Cells are capable of:
- Redrawing themselves as needed.
- Responding to mouse interactions.
- Performing other actions expected of a visual object.
The grid is divided into distinct areas—Title, Indicator, Footer, and Data—each with cells that have unique visual structures. To manage the creation and initialization of these cells, the grid employs CellManagers. Each CellManager is responsible for:
- Creating cells of a specific type.
- Initializing cells with appropriate content based on their position in the grid.
For example, a TDataGridTitleCellManagerEh creates cells for column headers, which may display:
- Header text.
- A sort indicator icon.
- A dropdown button for column filtering.
A CellManager retrieves relevant data for initialization. For instance, for a header in the second column, the CellManager fetches the header text from the DataGrid.Columns collection and assigns it to the TColumn.Title.Text property of the TextContent object within the cell's visual structure.
Grid Areas and Cell Customization
The following sections describe the grid's areas and how developers can customize cell content.
IndicatorTitle Section
The IndicatorTitle section is the top-left cell of the grid, typically displaying static information. It uses a CellManager of type TDataGridIndicatorTitleCellManagerEh.
Customization Options
- Override the CellManager: Assign a custom
CellManager, derived fromTDataGridIndicatorTitleCellManagerEh, to theTDataGridEh.IndicatorTitle.DefaultCellManagerproperty. - Event Handlers: Implement the
OnCreateCellContentandOnInitCellContentevent handlers forTDataGridEh.IndicatorTitle.DefaultCellManager. Note thatOnInitCellContentis typically unnecessary for this section due to its static nature.
IndicatorColumn Section
The IndicatorColumn section is the first column in the grid, displaying record numbers and the current record indicator. It uses a CellManager of type TDataGridIndicatorCellManagerEh.
Customization Options
- Override the CellManager: Assign a custom
CellManager, derived fromTDataGridIndicatorCellManagerEh, to theTDataGridEh.IndicatorColumn.DefaultCellManagerproperty. - Event Handlers: Implement the
OnCreateCellContentandOnCellInitContentevent handlers forTDataGridEh.IndicatorColumn.
Title Section
The Title section is the topmost non-scrollable row in the grid, displaying column headers. It uses a CellManager of type TDataGridTitleCellManagerEh.
Customization Options
- Override the CellManager: Assign a custom
CellManager, derived fromTDataGridTitleCellManagerEh, to theTDataGridEh.Title.DefaultCellManagerproperty. - Event Handlers: Implement the
OnCreateCellContentandOnCellInitContentevent handlers forTDataGridEh.Title. - Column-Specific Customization: To apply a unique format to specific columns:
- Create a descendant of
TDataGridTitleCellManagerEh. - Override the necessary methods.
- Instantiate the custom
CellManagerand assign it in theTDataGridEh.Title.OnGetCellManagerevent.
- Create a descendant of
Footer Section
The Footer section is the bottom non-scrollable row in the grid, displaying aggregate values for columns. It uses a CellManager of type TDataGridFooterCellManagerEh.
Customization Options
- Override the CellManager: Assign a custom
CellManager, derived fromTDataGridFooterCellManagerEh, to theTDataGridEh.Footer.DefaultCellManagerproperty.
Data Section
In the Data section, each column determines its own CellManager. For example:
- A
TDataGridStringColumnEhcolumn uses aCellManagerof typeTDataAxisTextCellManagerEh. - A
TDataGridCheckboxColumnEhcolumn uses aCellManagerof typeTDataAxisCheckboxCellManagerEh.
Customization Options
Custom CellManager for Specific Columns: Implement the
TDataGridColumnEh.OnGetDataCellManagerevent handler to assign a customCellManagerfor all Rows or for a specific Row.TDataGridLayoutColumnEh: This column type uses a default
CellManagerthat creates empty cells capable of rendering a blank background and multi-select highlighting. It is designed for developers to define custom cell content through events:- Create new
TDataGridLayoutColumnEhin the TDataGridEh - Content Creation: Implement the
TDataGridLayoutColumnEh.OnCreateDataCellContentevent handler to define the cell's content. - Content Initialization: Implement the
TDataGridLayoutColumnEh.OnDataCellInitContentevent handler to initialize the cell with data based on the current record number.
- Create new
Code Samples
To understand how to use events and classes to create cells with the structure you need, see the demo code and descriptions for them: Code Samples.
