# Multiple Cell Factory

## Content

Cell factories in FlexGrid provide a customization layer that controls cell rendering and interaction behavior. They can be used to implement advanced grid features such as conditional styling, filtering highlights, loading indicators, and dynamic UI elements.
In many applications, multiple grid features must operate together within the same FlexGrid instance. Since these features often depend on custom cell factories, FlexGrid provides a mechanism for composing multiple cell factories without overriding existing functionality.

## Built-in Cell Factories

FlexGrid includes several built-in behaviors that internally implement cell factories to extend grid functionality.
**Skeleton Loading**
The `SkeletonLoadingBehavior` implements a cell factory that displays placeholder content when a row's data item is not yet available. This behavior improves perceived responsiveness during data loading operations.
**Common Scenarios**

* Large datasets
* Asynchronous data loading

**Row Details**
The `FlexGridDetailProvider` behavior implements a cell factory that adds expandable row details. A toggle button is displayed in the row header to expand or collapse additional row content. While row details are loading, an activity indicator is displayed.
**Common Scenarios**

* Master-detail data presentation
* Lazy loading of row-specific content

**Check List**
The `CheckListBehavior` modifies cell selection behavior through a cell factory implementation. It enables checklist-style selection workflows for multiple items.
**Common Scenarios**

* Multi-selection workflows
* Task or item selection

**Full-Text Filter**
The `FullTextFilterBehavior` implements a cell factory that highlights text matching the current filter criteria, making matching content easier to identify.
**Common Scenarios**

* Search-intensive grids
* Data exploration interfaces

**Transposed Grid**
The `TransposedGridBehavior` uses a cell factory to transpose the grid layout by converting rows into columns and columns into rows.
**Common Scenarios**

* Pivot-style data presentation
* Improved readability for wide datasets

**Conditional Formatting**
The `ConditionalFormattingBehavior` from the ``` C1.``<span data-testid="definition-highlighter" class="_5pioz8co _189e1dm9 _1il9buyh _19lc184f _d0altlke" style="border-image: linear-gradient(90deg, rgb(0, 101, 255), rgb(191, 99, 243), rgb(245, 230, 168)) 0 0 100%; border-width: 1.6px; border-bottom-style: solid; --_11qfq0e: solid;">WPF</span>``.Grid.ConditionalFormatting ``` library implements a cell factory that applies styles based on defined rules and cell values.
**Common Scenarios**

* Highlighting trends or thresholds
* In-grid data visualization

## Compose Multiple Cell Factories

When multiple behaviors are applied to the same grid, their corresponding cell factories must work together without interfering with one another. FlexGrid provides a structured composition model for this scenario.
**GridLinkedCellFactory**
`GridLinkedCellFactory` is a specialized cell factory designed to chain multiple cell factories together. Instead of replacing existing rendering logic, it forwards execution to the next cell factory in the chain.
**Benefits**

* Enables multiple behaviors to operate together
* Preserves behavior-specific rendering logic
* Supports incremental customization

## Manage the Cell Factory Stack

FlexGrid traditionally exposed the `CellFactory` property for customization. However, directly assigning a new value to this property replaces any existing cell factories applied by behaviors and can disable built-in functionality.
To support multiple cell factories safely, FlexGrid provides a stack-based management approach.
**PushCellFactory Method**
The `PushCellFactory` method adds a cell factory to the top of the stack, ensuring it executes before previously registered cell factories.

```auto
public void PushCellFactory(GridLinkedCellFactory cellFactory){
}
```

**Usage Scenarios**

* Add custom rendering logic without overriding existing behaviors
* Extend grid functionality safely

**PopCellFactory Method**
The `PopCellFactory` method removes a specific cell factory from the stack.

```auto
public void PopCellFactory(GridLinkedCellFactory cellFactory){
}
```

**Usage Scenarios**

* Remove or disable custom behavior dynamically
* Clean up temporary customizations

**TopCellFactory Property**
In addition to the `CellFactory` property, FlexGrid provides the read-only `TopCellFactory` property. This property represents the top-most cell factory in the stack and is used internally to execute rendering logic.

### Usage Notes

* Reflects the currently active cell factory
* Supports advanced customization scenarios
* Maintains compatibility with existing implementations