Meta

Understanding the Meta Instance in Table Components

When working with dynamic tables, it's often necessary to store additional information about table elements — such as their original values, column names, or attributes that affect rendering — without modifying the actual displayed data. The Meta instance provides a structured way to store and retrieve such metadata efficiently.


What is the Meta Instance?

The Meta instance is an internal storage mechanism available to all table components, from the Table itself down to individual Td (table data) elements.

This is possible because all table elements implement the TableComponentInterface, which defines the following method:

interface TableComponentInterface extends RenderableInterface
{
    public function getMeta(): Meta;
}

This means that every table component can have additional, temporary, or shareable data stored in a Meta instance.

Although all elements support metadata, it is most commonly used in cells (Th, Td) since they contain the main data values.


Difference Between Meta and Data

Understanding the distinction between Meta and Data is essential:

Property Purpose Displayed in HTML Output?
Meta Holds additional information for orchestrating table behavior (e.g., original values, formatting rules, extra attributes). No
Data The actual value displayed in the table cell. Yes
Example:
$cell = new Td(43550); // Data in cents

// Store metadata
$cell->getMeta()->set('columnName', 'price');
$cell->getMeta()->set('originalValue', 43550);

$modifiedValue = number_format($cell->getMeta()->get('originalValue') / 100, 2);

// Modify the data while keeping metadata intact
$cell->setData($modifiedValue);

Rendered HTML Output:

<td>435.50</td>

Meta exists internally but does not affect the output.


Why Use Meta Instead of Modifying Data Directly?

  • Separation of Concerns – Keeps original data untouched while allowing flexible modifications.
  • Reusability – Metadata can be used by multiple middlewares without interfering with each other.
  • Consistency – When working with different adapters, Meta ensures a standardized way to access information.

Conclusion

The Meta instance is a powerful tool for managing extra cell information without altering the table structure. Whether you need to store original values, rename headers, or apply dynamic styles, Meta makes it easy to keep everything organized while ensuring only the necessary data appears in the final HTML output.

Source Code
If you find this project useful, consider leaving a on GitHub! Thank you!