Skip to content

Commit

Permalink
Refresh the README page
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreyu committed Jan 13, 2025
1 parent 5b9bb41 commit 230dcf5
Showing 1 changed file with 54 additions and 62 deletions.
116 changes: 54 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,54 @@
# DataTableBundle
<h1>
<p align="center">
<img width="75px" src="./docs/src/public/logo.png"/>
<br>DataTableBundle
</p>
</h1>

<img align="right" width="200px" src="./docs/src/public/logo.png"/>
<p align="center">
Streamlines the creation process of the data tables in Symfony applications.
<br />
<a href="#about">About</a>
·
<a href="https://data-table-bundle.swroblewski.pl/">Documentation</a>
·
<a href="https://data-table-bundle.swroblewski.pl/reference">Reference</a>
</p>
</p>

![Packagist Version](https://img.shields.io/packagist/v/kreyu/data-table-bundle?label=version&color=%237986CB&link=https%3A%2F%2Fpackagist.org%2Fpackages%2Fkreyu%2Fdata-table-bundle)

Streamlines the creation process of the data tables in Symfony applications.
## About

> [!WARNING]
> This bundle is still in development and is likely to **change**, or even **change drastically**.
> It is **NOT** production ready, and backwards compatibility is **NOT** guaranteed until the first stable release.
## Documentation

Check out the [official documentation](https://data-table-bundle.swroblewski.pl).

## Features
This bundle allows creating data tables in the same way as you probably do with forms, as
every component can be defined with a [type class] and reused across the application.

- [Type classes](https://data-table-bundle.swroblewski.pl/docs/introduction#similarity-to-form-component) for a class-based configuration, like in a Symfony Form component
- [Sorting](https://data-table-bundle.swroblewski.pl/docs/features/sorting), [filtering](https://data-table-bundle.swroblewski.pl/docs/features/filtering) and [pagination](https://data-table-bundle.swroblewski.pl/docs/features/pagination) - classic triforce of the data tables
- [Personalization](https://data-table-bundle.swroblewski.pl/docs/features/features/personalization) where the user decides the order and visibility of columns
- [Persistence](https://data-table-bundle.swroblewski.pl/docs/features/persistence) to save applied data (e.g. filters) between requests
- [Exporting](https://data-table-bundle.swroblewski.pl/docs/features/exporting) with or without applied pagination, filters and personalization
- [Theming](https://data-table-bundle.swroblewski.pl/docs/features/theming) of every part of the bundle using Twig
- [Data source agnostic](https://data-table-bundle.swroblewski.pl/docs/features/extensibility) with Doctrine ORM supported out of the box
- [Asynchronicity](https://data-table-bundle.swroblewski.pl/docs/features/asynchronicity) thanks to integration with Hotwire Turbo
[type class]: https://data-table-bundle.swroblewski.pl/docs/introduction#similarity-to-form-component

## Use cases
Data tables can be [sorted], [filtered] and [paginated]. Users can [personalize] the order
and visibility of columns. Those features can be [persisted] between requests, per user,
so closing the browser and coming back later will restore the previous state.

Imagine an application, that contains many listings - a list of products, categories, tags, clients, etc.
In most cases, we're returning a list of data to the view, and rendering it directly in the Twig.
Now, imagine, that the category details view should display a listing of its own products.
Some time later, the client requires a way to sort and filter the tables.
[sorted]: https://data-table-bundle.swroblewski.pl/docs/features/sorting
[filtered]: https://data-table-bundle.swroblewski.pl/docs/features/filtering
[paginated]: https://data-table-bundle.swroblewski.pl/docs/features/pagination
[personalize]: https://data-table-bundle.swroblewski.pl/docs/features/personalization
[persisted]: https://data-table-bundle.swroblewski.pl/docs/features/persistence

This quickly becomes less and less maintainable as the system grows.
With this bundle, you could define a data table for each entity, with their columns, filters, actions and exporters, each using a simple PHP class.
Reusing the data tables (and its components) is as easy, as reusing the forms using the Symfony Form component.
Works with Doctrine ORM and arrays out-of-the-box, but can be easily [integrated with any data source].
Supports [theming] with Twig and [exporting] to various data formats.

However, if your application is using an admin panel generator, like a SonataAdminBundle or EasyAdminBundle, you definitely **don't** need this bundle.
Those generators already cover the definition of data tables in their own way.
[integrated with any data source]: https://data-table-bundle.swroblewski.pl/docs/features/extensibility.html#proxy-queries
[theming]: https://data-table-bundle.swroblewski.pl/docs/features/theming
[exporting]: https://data-table-bundle.swroblewski.pl/docs/features/exporting

Sometimes applications are complex enough, that an admin generator would be either too simple, or too limiting.
This is a case where this bundle shines - you can build a fully customized application, while delegating all the data table oriented work to the bundle.

## Similarity to form component
> [!WARNING]
> This bundle is still in development and is likely to **change**, or even **change drastically**.
> It is **NOT** production ready, and backwards compatibility is **NOT** guaranteed until the first stable release.
Everything is designed to be friendly to a Symfony developers that used the [Symfony Form component](https://github.com/symfony/form/) before.

> [!NOTE]
> There are **many** similarities between those components - even in the source code!
> Thanks to that, it should be easy to work with the bundle, and contribute as well.
>
> Credits to all the creators and contributors of the [Symfony Form component](https://github.com/symfony/form/),
> as they are the ones that came up with the idea of this type-based configuration, and this bundle only follows its principles.
>
> Although, because Form component can be used outside a framework, and this bundle works only as a Symfony bundle,
> the core is simplified as much as possible.
## Familiarity

Data tables and their components - columns, filters, actions and exporters, are defined using type classes, like a forms:
If you've ever worked with forms in Symfony, you should feel right at home:

```php
class ProductDataTableType extends AbstractDataTableType
Expand All @@ -65,20 +57,13 @@ class ProductDataTableType extends AbstractDataTableType
{
$builder
->addColumn('id', NumberColumnType::class)
->addColumn('name', TextColumnType::class);

$builder
->addFilter('id', NumericFilterType::class)
->addFilter('name', StringFilterType::class);

$builder
->addAction('create', ButtonActionType::class)
->addRowAction('update', ButtonActionType::class)
->addBatchAction('delete', ButtonActionType::class);

$builder
->addExporter('csv', CsvExporterType::class)
->addExporter('xlsx', XlsxExporterType::class);
->addColumn('name', TextColumnType::class)
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefault('translation_domain', 'product');
}
}
```
Expand All @@ -90,11 +75,17 @@ class ProductController extends AbstractController
{
use DataTableFactoryAwareTrait;

public function index(Request $request): Response
public function index(Request $request, ProductRepository $repository): Response
{
$dataTable = $this->createDataTable(ProductDataTableType::class, $query);
$queryBuilder = $repository->createDataTableQueryBuilder();

$dataTable = $this->createDataTable(ProductDataTableType::class, $queryBuilder);
$dataTable->handleRequest($request);

if ($dataTable->isExporting()) {
return $this->file($dataTable->export());
}

return $this->render('product/index.html.twig', [
'products' => $dataTable->createView(),
])
Expand All @@ -111,6 +102,7 @@ Rendering the data table in Twig is as simple as executing a single function:
</div>
```


## License

The MIT License (MIT). Please see [license file](LICENSE) for more information.

0 comments on commit 230dcf5

Please sign in to comment.