Livewire PowerGrid

repository·6.x·Indexed 23 days ago

https://github.com/power-components/livewire-powergrid

A powerful data table component for Laravel applications built on Livewire. It enables the creation of advanced datatables with features including sorting, filtering, inline editing, pagination, and data exporting to XLSX/CSV via OpenSpout. It supports Tailwind CSS and Bootstrap 5, and provides CLI tools for component generation and asset publishing.

Tokens
2.8K
Snippets
4
Records
21
Agent score
82%

What's inside livewire-powergrid

  1. Overview of PowerGrid features

    6.x

    Livewire PowerGrid is a library for creating advanced, customizable data tables in Laravel using Livewire. It supports both Tailwind CSS and Bootstrap 5 and includes several built-in features:

    • Core Table Functionality: Pagination, Column Sorting, and Responsive design.
    • Filtering & Search: Global search, custom filter builders, and column-specific data filters.
    • Interactivity: Inline editing (click-to-edit), row buttons, checkboxes, dropdown menus, and toggle switches.
    • Data Management: Multi-row bulk actions, conditional action rules, and column summaries (Sum, Count, Average).
    • Exporting: Data export to XLSX/CSV using OpenSpout, including support for queued exports for large datasets.
    • Integrations: Livewire Modal integration (via Wire Elements Modal) and multi-language support.
  2. Install Livewire PowerGrid

    6.x

    To add PowerGrid to your Laravel project, require the package via Composer. After installation, you must follow the specific setup steps provided in the official documentation to ensure assets and configurations are correctly initialized.

    composer require power-components/livewire-powergrid
  3. How column visibility affects exports

    6.x

    When preparing an export using the prepare method, the visibility of a column is determined by the following logic:

    1. If a column has visibleInExport set to true, it will be included.
    2. If a column is not hidden (!$column->hidden) and visibleInExport is null, it will be included, provided that no row-level export rules disable it.
    3. Row-level rules: The export process checks for a __powergrid_rules key on the data row. If the last rule where 'apply' => true has 'disable' => true, the column may be excluded for that specific row.

    Additionally, the prepare method can automatically strip HTML tags from exported values if the $stripTags parameter is set to true.

  4. Export data to XLS via ExportToXLS

    6.x

    The ExportToXLS class allows you to export PowerGrid data into an .xlsx file using the OpenSpout v5 engine. You can trigger a download by calling the download method, passing either an Exportable object or an array of export options.

    Export Options

    When passing an array to download(), you can configure the following options:

    • deleteFileAfterSend (bool): If true, the temporary .xlsx file will be deleted from storage after the response is sent.
    • striped (string/bool): Enables striped rows in the Excel file.
    • columnWidth (array): An associative array mapping column indices to widths (e.g., [0 => 20, 1 => 50]).
    • stripTags (bool): If true, HTML tags will be stripped from the data before exporting.
  5. Export data to XLSX using ExportToXLS

    6.x

    The ExportToXLS class allows you to export PowerGrid data into an Excel (.xlsx) file using the OpenSpout v4 engine. You can trigger a download or build the file by passing an Exportable instance or an array of options to the download() or build() methods.

    Available Export Options

    When passing an array to download() or build(), you can use the following keys:

    KeyTypeDescription
    deleteFileAfterSendboolIf true, the generated .xlsx file will be deleted from storage after the response is sent.
    stripedstringA hex color string (e.g., 'f0f0f0') used for zebra-striping rows if striping is enabled.
    columnWidtharray<int, float>An associative array where keys are column indices (starting at 1) and values are the desired widths.
    stripTagsboolIf true, HTML tags will be stripped from the data before exporting.

    Usage Example

    // Example of triggering an XLSX download with custom options
    $exportOptions = [
        'deleteFileAfterSend' => true,
        'striped' => 'd0d3d8',
        'columnWidth' => [1 => 20, 2 => 30],
        'stripTags' => true,
    ];
    
    return $exportToXls->download($exportOptions);
  6. Export data to CSV using ExportToCsv

    6.x

    The ExportToCsv class allows you to export PowerGrid data into a CSV file using the OpenSpout v4 engine. You can trigger a download or build the file manually by passing an Exportable instance or an array of options.

    Available Export Options

    When passing an array to download() or build(), you can use the following keys:

    KeyTypeDefaultDescription
    deleteFileAfterSendboolfalseIf true, the temporary CSV file will be deleted from storage after the response is sent.
    stripTagsboolfalseIf true, HTML tags will be stripped from the data before exporting.
    csvSeparatorstring','The character used to separate fields in the CSV.
    csvDelimiterstring'"'The character used to enclose fields (enclosure).
  7. Configure data exports with the Export class

    6.x

    The Export class is used to prepare data for export operations. You can configure the export by setting the file name, the data collection, and the columns to be included.

    Key methods:

    • fileName(string $name): Sets the name of the exported file.
    • setData(array $columns, Collection $data): Sets the columns (an array of Column objects) and the data collection to be used in the export.
    • prepare(Collection $data, array $columns, bool $stripTags): Processes the provided data and columns into a structured array containing 'headers' and 'rows'. If $stripTags is set to true, HTML tags will be removed from the values.