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

Livewire Powergrid Laravel Package

power-components/livewire-powergrid

Livewire PowerGrid lets you build modern, customizable data tables for Laravel Livewire in minutes. Get sorting, searching, filters, editable fields, action buttons, checkboxes, and export with minimal configuration—ready to use out of the box.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer: composer require power-components/livewire-powergrid. Publish the config and assets: php artisan vendor:publish --tag=powergrid-config and --tag=powergrid-public. Create a PowerGrid table class using the Artisan command: php artisan make:power-grid-table PostTable. In your Blade view, render the table with @livewire('post-table').

Start with the minimal example: define columns (addColumns), data source (DataSource), and basic formatting. For new features, explore lifecycle hooks (e.g., transformQuery, transformActions, transformRows) and custom search handlers in your table class. Note: If using a Collection datasource, ensure your datasource() method does not trigger duplicate calls (fixed in v6.10.1).


Implementation Patterns

Use PowerGridComponent as the base class for all tables. Define data sources imperatively using Eloquent models, collections, or raw queries via datasource().

New Features:

  • Lifecycle Hooks: Leverage transformQuery, transformActions, and transformRows to modify behavior dynamically. For example, use transformQuery to inject custom query scopes or modify the query builder before execution.
    public function transformQuery($query)
    {
        $query->where('active', true);
    }
    
  • Custom Search Handlers: Replace the default SearchHandler with your own implementation for advanced search logic. Define it in your table class:
    public function searchHandler()
    {
        return new CustomSearchHandler();
    }
    
  • Responsive Design: Enable responsive mode in config and use Tailwind classes for mobile column toggles. For bulk actions, use batchActions() and ensure they align with your custom search logic.
  • Custom Rendering: Use detail(), header(), or footer() slots for expandable rows or totals. For complex rendering, use th() or td() closures with caution—return plain strings or valid HTML.

Data Source Fix (v6.10.1):

  • Collection Datasource: Previously, the datasource() method was called twice when using a Collection. This has been fixed in v6.10.1. No additional action is required unless you were explicitly relying on this behavior.

Gotchas and Tips

Updated Gotchas:

  • Lifecycle Hooks: Avoid infinite loops or unintended side effects when modifying queries/actions/rows. Test hooks thoroughly, especially in transformQuery, as they execute before data fetching.
  • Custom Search Handlers: Ensure your custom handler extends SearchHandler or implements the required methods. Debug by logging search payloads in the handler’s handle() method.
  • Livewire Limitations: Still avoid large JSON payloads in mount()—initialize data lazily with DataSource. Use remember() sparingly, as it can cause stale data if not paired with cache invalidation or reactivity.
  • Collection Datasource: In versions prior to v6.10.1, the datasource() method was called twice when using a Collection. If you were debugging or relying on this behavior, ensure your logic is updated to avoid duplicate operations.

Debugging Tips:

  • Enable dd() in lifecycle hooks (e.g., transformQuery) for debugging, but remove before production.
  • For custom search handlers, log the $search parameter in handle() to verify input:
    public function handle($search)
    {
        \Log::debug('Search payload:', $search);
        // Custom logic here
    }
    
  • If experiencing unexpected behavior with Collection datasources, verify your datasource() method is not being called redundantly (fixed in v6.10.1).

Extension Points:

  • Blade Components: Extend functionality by publishing and modifying Blade components (pg-{component}) in resources/vendor/powergrid.
  • Query Modification: Use transformQuery to inject soft deletes, scopes, or conditional clauses dynamically.
  • Row Transformation: Use transformRows to modify row data before rendering (e.g., formatting dates or adding computed fields). Example:
    public function transformRows($rows)
    {
        return $rows->map(function ($row) {
            $row->formatted_date = $row->created_at->format('Y-m-d');
            return $row;
        });
    }
    
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope