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

Dynamic Datatables Bundle Laravel Package

ahmedsamy/dynamic-datatables-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require ahmedsamy/dynamic-datatables-bundle
    

    Add to AppKernel.php (Symfony 2.x):

    new AhmedSamy\DynamicDataTablesBundle\DynamicDataTablesBundle(),
    
  2. Basic Controller Usage Create a controller method to handle DataTable requests:

    use AhmedSamy\DynamicDataTablesBundle\DataTables;
    
    public function indexAction(Request $request)
    {
        $dataTables = new DataTables();
        $dataTables->setDataSource($this->getDoctrine()->getRepository('AppBundle:YourEntity')->findAll());
        return $dataTables->getResponse();
    }
    
  3. Frontend Integration Include jQuery, DataTables JS/CSS, and initialize:

    $(document).ready(function() {
        $('#yourTable').DataTable({
            processing: true,
            serverSide: true,
            ajax: {
                url: "{{ path('your_route') }}",
                type: 'POST'
            }
        });
    });
    
  4. Routing Define a route for the DataTable endpoint:

    your_route:
        path: /api/datatables
        defaults: { _controller: 'AppBundle:YourController:index' }
    

Implementation Patterns

Common Workflows

  1. Doctrine Integration Use setDataSource() with Doctrine repositories or custom queries:

    $dataTables->setDataSource(
        $this->getDoctrine()
            ->getRepository('AppBundle:User')
            ->createQueryBuilder('u')
            ->getQuery()
    );
    
  2. Column Customization Define columns via annotations or YAML:

    # config.yml
    ahmedsamy_dynamic_datatables:
        columns:
            user:
                - { property: 'id', title: 'ID' }
                - { property: 'email', title: 'Email' }
                - { property: 'createdAt', title: 'Created At' }
    
  3. Server-Side Processing Leverage built-in server-side logic for sorting, filtering, and pagination:

    $dataTables->setServerSide(true); // Enable server-side processing
    
  4. Custom Actions Add buttons/links to rows via setRowActions():

    $dataTables->setRowActions([
        'edit' => ['route' => 'edit_user', 'params' => ['id' => 'id']],
        'delete' => ['route' => 'delete_user', 'params' => ['id' => 'id']]
    ]);
    
  5. Event Listeners Extend functionality with events (e.g., pre/post fetch):

    $dataTables->addListener('preFetch', function($event) {
        $event->setDataSource($this->customFilter($event->getDataSource()));
    });
    

Gotchas and Tips

Pitfalls

  1. Symfony 2.x Only

    • Package targets Symfony 2.x (not 3.x/4.x/5.x). Avoid using with newer Symfony versions without compatibility checks.
  2. Doctrine ORM Dependency

    • Assumes Doctrine ORM for data fetching. For non-Doctrine projects, manually implement setDataSource() logic.
  3. Limited Documentation

    • Minimal docs; rely on source code (src/AhmedSamy/DynamicDataTablesBundle/) for advanced use cases.
  4. CSRF Issues

    • Server-side processing may conflict with Symfony’s CSRF protection. Disable for DataTable routes:
      # config.yml
      framework:
          csrf_protection:
              enabled: false
      
  5. Performance Overhead

    • Server-side processing loads entire datasets into memory. Optimize with:
      $dataTables->setLimit(100); // Reduce fetch size
      

Debugging Tips

  1. Enable Verbose Logging

    $dataTables->setDebug(true); // Logs SQL queries and processing steps
    
  2. Check Request Data Dump raw DataTable request payload:

    $requestData = $request->request->all();
    // dd($requestData); // Uncomment for debugging
    
  3. Validate Column Mappings Ensure YAML/annotation column properties match entity fields exactly (case-sensitive).

Extension Points

  1. Custom Data Sources Implement AhmedSamy\DynamicDataTablesBundle\DataSourceInterface for non-Doctrine data:

    class CustomDataSource implements DataSourceInterface {
        public function fetch($offset, $length, $columns, $order, $search) {
            // Custom logic
        }
    }
    
  2. Override Templates Extend Twig templates (e.g., row_actions.html.twig) in templates/AhmedSamyDynamicDataTablesBundle/.

  3. Add Custom Events Extend the event system for pre/post-processing:

    $dataTables->addListener('postFetch', function($event) {
        $event->setData($this->transformData($event->getData()));
    });
    
  4. Localization Override translations in Resources/translations/ for multi-language support.

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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle