Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Grid Bundle Laravel Package

avpretty/grid-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require avpretty/grid-bundle
    

    Enable the bundle in config/bundles.php:

    return [
        // ...
        AlexyAV\GridBundle\AVGridBundle::class => ['all' => true],
    ];
    
  2. First Use Case: Display a Doctrine entity as a table in Twig:

    {{ av_grid({
        'data': app.doctrine.orm.entity_manager.getRepository('App\Entity\Post').findAll(),
        'columns': [
            { 'name': 'id', 'label': 'ID' },
            { 'name': 'title', 'label': 'Title' },
            { 'name': 'createdAt', 'label': 'Created At', 'type': 'date' }
        ]
    }) }}
    
  3. Key Files:

    • config/av_grid.yml (default configuration)
    • templates/AVGridBundle/grid.html.twig (customize via twig.config.paths)

Implementation Patterns

Common Workflows

  1. Dynamic Column Generation: Use a closure to define columns dynamically:

    {{ av_grid({
        'data': posts,
        'columns': [
            { 'name': 'id', 'label': 'ID' },
            { 'name': 'title', 'label': 'Title' },
            {
                'name': 'actions',
                'label': 'Actions',
                'type': 'actions',
                'actions': [
                    { 'route': 'post_edit', 'label': 'Edit' },
                    { 'route': 'post_delete', 'label': 'Delete', 'icon': 'trash' }
                ]
            }
        ]
    }) }}
    
  2. Pagination & Sorting: Enable via config (av_grid.yml):

    default:
        pagination: true
        per_page: 10
        sortable: true
    

    Use in Twig:

    {{ av_grid({
        'data': paginatedPosts,
        'pagination': {
            'route': 'post_index',
            'page_param': 'page'
        }
    }) }}
    
  3. Custom Cell Rendering: Override Twig templates or use cell_type:

    {{ av_grid({
        'columns': [
            {
                'name': 'status',
                'label': 'Status',
                'cell_type': 'App\\GridBundle\\Twig\\StatusCellType'
            }
        ]
    }) }}
    
  4. Integration with Forms: Embed grids in forms for bulk actions:

    {{ form_start(form) }}
        {{ av_grid({
            'data': posts,
            'checkbox': true,
            'checkbox_name': 'posts[]'
        }) }}
        {{ form_widget(form.submit) }}
    {{ form_end(form) }}
    

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony Versions:

    • Only supports Symfony 2.3–3.0. Avoid in newer projects without compatibility checks.
    • Fix: Use a wrapper or fork if targeting Symfony 4+/5+.
  2. Twig Template Overrides:

    • Custom templates must extend AVGridBundle:grid:base.html.twig.
    • Debugging: Clear cache (php bin/console cache:clear) after template changes.
  3. Performance with Large Datasets:

    • Pagination is optional; disable if not needed (pagination: false).
    • Tip: Use hydration_mode: LAZY in Doctrine queries for grids.
  4. Column Naming Conflicts:

    • If name in columns matches a non-existent property, the cell renders empty.
    • Fix: Use getter or setter options:
      { 'name': 'full_name', 'getter': 'getFullName' }
      

Debugging Tips

  1. Enable Debug Mode:

    # config/packages/av_grid.yml
    debug: true
    

    Logs column rendering issues to Symfony’s profiler.

  2. Check Configuration: Validate av_grid.yml for typos (e.g., per_page vs. items_per_page).

  3. Common Errors:

    • "Column not found": Ensure name matches the entity property or getter.
    • Empty grid: Verify data is an array of objects/arrays, not null.

Extension Points

  1. Custom Cell Types: Create a service tagged as av_grid.cell_type:

    # config/services.yaml
    services:
        App\GridBundle\Cell\CustomCellType:
            tags:
                - { name: av_grid.cell_type, alias: 'custom' }
    
  2. Event Listeners: Hook into av_grid.pre_render to modify data before rendering:

    // src/EventListener/GridListener.php
    public function onPreRender(GridEvent $event) {
        $event->setData(array_map(fn($item) => [...], $event->getData()));
    }
    

    Register in services.yaml:

    tags:
        - { name: kernel.event_listener, event: av_grid.pre_render, method: onPreRender }
    
  3. Asset Management: Override CSS/JS by publishing assets:

    php bin/console assets:install
    

    Then extend grid.scss in web/css/av_grid/.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle