Features

The Table Generator package is a powerful and flexible library designed to simplify the creation of HTML tables in PHP. It includes various components and tools that make it both beginner-friendly and highly customizable for advanced developers. Below are some key features:

1. Adapters for Data Source

Adapters allow Table Generator to retrieve and format data from different sources. Instead of manually structuring your table data, you can use an adapter to automatically populate it. Supported adapters include:

  • CsvArrayAdapterProcesses CSV-like data.
  • AssocArrayAdapterConverts associative arrays into table format.
  • MysqliResultAdapterDirectly converts MySQL query results into a table.

Custom adapters can be created to support other data formats.


2. Middleware for Data Transformation

Middleware allows you to modify or enhance table data before rendering. This feature is useful for formatting values, translating text, or even injecting additional columns dynamically. It is a fundamental part of Ucscode Table Generator which enhances flexibility when working with fixed data sources. Example of cases where middleware may be required:

  • Formatting table values.
  • Adding extra columns dynamically.
  • Filtering or transforming data.
  • Including checkboxes for each table row

3. Automatic Pagination Support

The Table Generator library integrates seamlessly with ucscode/easy-paginator, making it easy to add pagination to large datasets. You can set the number of rows per page and navigate through the table efficiently.

  • Includes built-in support for paginating large datasets.
  • Makes handling large tables more efficient.

4. Component-Based Table Structure

The library provides PHP classes that directly represent HTML table elements, allowing fine-grained control over table construction. For example:

  • new Thead() represents <thead>
  • new Th() represents <th>

5. Collection Management

In the occassion where elements can be multiple, collection classes are used to manage the associated elements. This ensures proper structure and organization of table elements. For example:

  • TrCollection for handling multiple <tr> elements.
  • TbodyCollection for managing multiple <tbody> sections.

6. Customizable Rendering

The Table Generator:

  • Provides a simple way to render the table as a complete HTML string.
  • Supports setting attributes such as classes, styles, and IDs.
  • Supports easy application of colspan, rowspan, and other advanced table features.
  • Can be customized with additional wrappers and styles.

7. Easy Integration with Other PHP Applications

  • Works seamlessly with various PHP applications and frameworks.
  • Can be extended with custom functionality using adapters and middleware.

8. Beginner-Friendly and Advanced Developer Features

  • A complete table skeleton (without classes or attributes) can be generated with a single line of code:

    echo (new TableGenerator(new MysqliResultAdapter($result)))->render();
  • Advanced techniques can be implemented to:

    • Extend functionality with middleware.
    • Create custom adapters.
    • Manipulate table objects dynamically.

This combination of features makes Ucscode Table Generator a versatile and scalable solution for handling table generation in PHP.

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