An open API service indexing awesome lists of open source software.

https://github.com/picobaz/gridview

GridView: A flexible Laravel data grid component for dynamic tables. Supports pagination, filtering, sorting, and exports to CSV/Excel/PDF. Build sleek data displays with ease!
https://github.com/picobaz/gridview

csv-export data-grid excel-export filtering laravel pagination pdf-export php sorting table-widget

Last synced: 23 days ago
JSON representation

GridView: A flexible Laravel data grid component for dynamic tables. Supports pagination, filtering, sorting, and exports to CSV/Excel/PDF. Build sleek data displays with ease!

Awesome Lists containing this project

README

          

# ๐ŸŽฏ GridView

### *The Ultimate Data Grid Package for Laravel*

[![Latest Version on Packagist](https://img.shields.io/packagist/v/picobaz/gridview.svg?style=for-the-badge&logo=packagist)](https://packagist.org/packages/picobaz/gridview)
[![Total Downloads](https://img.shields.io/packagist/dt/picobaz/gridview.svg?style=for-the-badge&logo=packagist)](https://packagist.org/packages/picobaz/gridview)
[![License](https://img.shields.io/packagist/l/picobaz/gridview.svg?style=for-the-badge)](https://packagist.org/packages/picobaz/gridview)
[![PHP Version](https://img.shields.io/packagist/php-v/picobaz/gridview.svg?style=for-the-badge&logo=php)](https://packagist.org/packages/picobaz/gridview)
[![Laravel Version](https://img.shields.io/badge/Laravel-8%2B%20%7C%209%20%7C%2010%20%7C%2011%20%7C%2012-FF2D20?style=for-the-badge&logo=laravel)](https://laravel.com)

**Build powerful, flexible, and beautiful data tables in Laravel with ease!**

[Installation](#-installation) โ€ข [Quick Start](#-quick-start) โ€ข [Features](#-features) โ€ข [Documentation](#-documentation) โ€ข [Examples](#-examples) โ€ข [Support](#-support)

---

## ๐ŸŒŸ Why GridView?

GridView transforms your boring data tables into **powerful, interactive data grids** with just a few lines of code. Whether you're building an admin panel, a dashboard, or any data-intensive application, GridView has got you covered!

### โœจ Key Highlights

- ๐Ÿš€ **Lightning Fast** - Optimized for performance with large datasets
- ๐ŸŽจ **Beautiful UI** - Modern, responsive design out of the box
- ๐Ÿ” **Advanced Filtering** - Search and filter with ease
- ๐Ÿ“Š **Smart Sorting** - Multi-column sorting support
- ๐Ÿ“ค **Export Anywhere** - CSV, Excel, and PDF exports
- โœ๏ธ **Inline Editing** - Edit data without leaving the table
- โ˜‘๏ธ **Bulk Actions** - Perform actions on multiple rows at once
- ๐ŸŽฏ **Highly Customizable** - Style it your way
- ๐Ÿ“ฑ **Responsive** - Looks great on all devices
- ๐Ÿ” **Secure** - Built with security best practices

---

## ๐Ÿ“ฆ Installation

Install via Composer:

```bash
composer require picobaz/gridview
```

### Publish Assets (Optional)

```bash
# Publish configuration
php artisan vendor:publish --tag=gridview-config

# Publish views (for customization)
php artisan vendor:publish --tag=gridview-views

# Publish JavaScript/CSS assets
php artisan vendor:publish --tag=gridview-assets
```

---

## ๐Ÿš€ Quick Start

### Step 1: Create a Search Model

Generate a search model for your data:

```bash
php artisan make:gridview-search UserSearch
```

This creates `app/SearchModel/UserSearch.php`:

```php
function ($query, $value) {
return $query->where('name', 'LIKE', "%{$value}%");
},
'email' => function ($query, $value) {
return $query->where('email', 'LIKE', "%{$value}%");
},
'status' => function ($query, $value) {
return $query->where('status', $value);
},
];
}
}
```

### Step 2: Controller Setup

```php
use App\Models\User;
use App\SearchModel\UserSearch;

public function index()
{
$users = User::query();
$searchModel = new UserSearch();
$dataProvider = $searchModel->search($users);

return view('users.index', compact('searchModel', 'dataProvider'));
}
```

### Step 3: Blade View

```php
{!! gridview([
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
'export' => true,
'columns' => [
// Serial number column
['class' => \Picobaz\GridView\SerialColumns::class],

// Bulk action checkbox
[
'class' => \Picobaz\GridView\BulkActionColumn::class,
'checkboxOptions' => [
'name' => 'selection[]',
'class' => 'gridview-checkbox'
]
],

// Regular columns
[
'label' => 'Name',
'attribute' => 'name',
'sortable' => true,
],
[
'label' => 'Email',
'attribute' => 'email',
'sortable' => true,
],

// Inline editable column
[
'label' => 'Status',
'attribute' => 'status',
'editable' => true,
'editableType' => 'select',
'editableOptions' => [
'source' => [
['value' => 'active', 'text' => 'Active'],
['value' => 'inactive', 'text' => 'Inactive']
]
]
],

// Action buttons
[
'label' => 'Actions',
'value' => function($model) {
return '

Edit


View

';
}
],
]
]) !!}

{{-- Bulk Actions Toolbar --}}



0 items selected



Delete Selected



Activate

{{-- Add model class for bulk actions --}}


```

**That's it!** ๐ŸŽ‰ You now have a fully functional data grid with filtering, sorting, pagination, and export capabilities!

---

## ๐ŸŽฏ Features

### ๐Ÿ“Š Smart Data Table

Create beautiful, responsive data tables with minimal code:

```php
{!! gridview([
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
'tableOptions' => ['class' => 'table table-striped'],
'columns' => [...]
]) !!}
```

### ๐Ÿ” Advanced Filtering

Filter data with custom search rules:

```php
public function searchRules(): array
{
return [
'name' => function ($query, $value) {
return $query->where('name', 'LIKE', "%{$value}%");
},
'category_id' => function ($query, $value) {
return $query->whereHas('category', function ($q) use ($value) {
$q->where('id', $value);
});
},
'price_range' => function ($query, $value) {
[$min, $max] = explode('-', $value);
return $query->whereBetween('price', [$min, $max]);
},
];
}
```

### ๐Ÿ“ˆ Multi-Column Sorting

```php
[
'label' => 'Name',
'attribute' => 'name',
'sortable' => true,
]
```

### ๐Ÿ“ค Export to Multiple Formats

Export your data to CSV, Excel, or PDF:

```php
{!! gridview([
'export' => true,
'exportColumns' => [
'Name' => 'name',
'Email' => 'email',
'Status' => 'status',
]
]) !!}
```

### โœ๏ธ Inline Editing (NEW! ๐Ÿ”ฅ)

Edit data directly in the table without navigating away:

```php
[
'label' => 'Title',
'attribute' => 'title',
'editable' => true,
'editableType' => 'text', // text, number, email, date, select, textarea
'editableUrl' => route('gridview.inline.update'),
]
```

**Select dropdown example:**

```php
[
'label' => 'Status',
'attribute' => 'status',
'editable' => true,
'editableType' => 'select',
'editableOptions' => [
'source' => [
['value' => 'pending', 'text' => 'Pending'],
['value' => 'approved', 'text' => 'Approved'],
['value' => 'rejected', 'text' => 'Rejected']
]
]
]
```

### โ˜‘๏ธ Bulk Actions (NEW! ๐Ÿ”ฅ)

Perform actions on multiple rows at once:

```php
// Add bulk action column
[
'class' => \Picobaz\GridView\BulkActionColumn::class,
'checkboxOptions' => [
'name' => 'selection[]'
]
]

// Add bulk action buttons

Delete Selected

Activate Selected

```

### ๐ŸŽจ Custom Column Rendering

```php
[
'label' => 'Avatar',
'value' => function($model) {
return '';
},
'format' => 'raw'
]
```

### ๐Ÿ”ง Custom Filters

Create custom filter views:

```php
[
'label' => 'Status',
'attribute' => 'status',
'filterView' => 'vendor.gridview.filters.status_filter',
]
```

**Custom filter view:**

```blade
{{-- resources/views/vendor/gridview/filters/status_filter.blade.php --}}


All

Active


Inactive

```

---

## ๐ŸŽจ Customization

### Styling

Customize table appearance in `config/gridview.php`:

```php
'styles' => [
'table_class' => 'table table-striped table-hover',
'header_class' => 'thead-dark',
'row_class' => 'table-row',
],
```

### Pagination

```php
'pagination' => [
'per_page' => 30,
'per_page_options' => [10, 20, 30, 50, 100],
],
```

### Icons

```php
'icons' => [
'sort_asc' => 'fa fa-sort-up',
'sort_desc' => 'fa fa-sort-down',
'export' => 'fa fa-download',
],
```

---

## ๐Ÿ“š Advanced Examples

### Example 1: E-commerce Products Grid

```php
{!! gridview([
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
'export' => true,
'columns' => [
['class' => \Picobaz\GridView\SerialColumns::class],
['class' => \Picobaz\GridView\BulkActionColumn::class],

[
'label' => 'Image',
'value' => function($model) {
return '';
},
'format' => 'raw',
],
[
'label' => 'Product Name',
'attribute' => 'name',
'sortable' => true,
'editable' => true,
'editableType' => 'text',
],
[
'label' => 'Category',
'attribute' => 'category.name',
'sortable' => true,
],
[
'label' => 'Price',
'attribute' => 'price',
'sortable' => true,
'editable' => true,
'editableType' => 'number',
'value' => function($model) {
return '$' . number_format($model->price, 2);
}
],
[
'label' => 'Stock',
'attribute' => 'stock',
'sortable' => true,
'value' => function($model) {
$class = $model->stock > 10 ? 'success' : ($model->stock > 0 ? 'warning' : 'danger');
return ''.$model->stock.'';
},
'format' => 'raw',
],
[
'label' => 'Status',
'attribute' => 'status',
'editable' => true,
'editableType' => 'select',
'editableOptions' => [
'source' => [
['value' => 'active', 'text' => 'Active'],
['value' => 'inactive', 'text' => 'Inactive'],
['value' => 'draft', 'text' => 'Draft']
]
],
'value' => function($model) {
$badges = [
'active' => 'success',
'inactive' => 'danger',
'draft' => 'secondary'
];
return ''
. ucfirst($model->status) . '
';
},
'format' => 'raw',
],
[
'label' => 'Actions',
'value' => function($model) {
return '






';
},
'format' => 'raw',
],
],
'exportColumns' => [
'ID' => 'id',
'Product Name' => 'name',
'Category' => 'category.name',
'Price' => 'price',
'Stock' => 'stock',
'Status' => 'status',
]
]) !!}
```

### Example 2: User Management Grid

```php
{!! gridview([
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
'columns' => [
['class' => \Picobaz\GridView\SerialColumns::class],
['class' => \Picobaz\GridView\BulkActionColumn::class],

[
'label' => 'Avatar',
'value' => function($model) {
return '';
},
'format' => 'raw',
],
[
'label' => 'Name',
'attribute' => 'name',
'sortable' => true,
'editable' => true,
],
[
'label' => 'Email',
'attribute' => 'email',
'sortable' => true,
],
[
'label' => 'Role',
'attribute' => 'role',
'editable' => true,
'editableType' => 'select',
'editableOptions' => [
'source' => [
['value' => 'admin', 'text' => 'Admin'],
['value' => 'user', 'text' => 'User'],
['value' => 'moderator', 'text' => 'Moderator']
]
]
],
[
'label' => 'Joined',
'attribute' => 'created_at',
'sortable' => true,
'value' => function($model) {
return $model->created_at->format('M d, Y');
}
],
]
]) !!}
```

---

## โš™๏ธ Configuration

Full configuration options in `config/gridview.php`:

```php
return [
'styles' => [...],
'pagination' => [...],
'export' => [...],
'bulk_actions' => [
'enabled' => true,
'default_actions' => [...]
],
'inline_editing' => [
'enabled' => true,
'auto_save' => true,
],
'search' => [
'debounce_delay' => 300,
'min_characters' => 2,
],
'cache' => [
'enabled' => false,
'ttl' => 3600,
],
];
```

---

## ๐Ÿ”’ Security

GridView takes security seriously:

- โœ… CSRF protection on all forms
- โœ… XSS prevention with proper escaping
- โœ… SQL injection prevention via Eloquent
- โœ… Fillable attribute checking for inline editing
- โœ… Model class validation

### Inline Edit Security

The package validates:
- Model class exists
- Attribute is fillable
- User has permission (implement your own middleware)

---

## ๐Ÿงช Testing

```bash
composer test
```

---

## ๐Ÿ“– Requirements

- PHP >= 7.3 | 8.0+
- Laravel >= 8.0 | 9.0 | 10.0 | 11.0 | 12.0
- maatwebsite/excel >= 3.1

---

## ๐Ÿค Contributing

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

### How to Contribute

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

---

## ๐Ÿ“ Changelog

Please see [CHANGELOG.md](CHANGELOG.md) for recent changes.

### v1.3.0 (Latest)
- โœจ Added Bulk Actions feature
- โœจ Added Inline Editing capability
- ๐Ÿ”ง Improved performance for large datasets
- ๐Ÿ› Bug fixes and improvements

---

## ๐Ÿ’ฌ Support

Need help? Have questions?

- ๐Ÿ“ง Email: [picobaz3@gmail.com](mailto:picobaz3@gmail.com)
- ๐Ÿ’ฌ Telegram: [@picobaz](https://t.me/picobaz)
- ๐Ÿ› Issues: [GitHub Issues](https://github.com/PicoBaz/gridview/issues)
- โญ Star us on [GitHub](https://github.com/PicoBaz/gridview)

---

## ๐Ÿ“„ License

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

---

## ๐ŸŒŸ Show Your Support

If you find GridView helpful, please consider:

- โญ Starring the repository on [GitHub](https://github.com/PicoBaz/gridview)
- ๐Ÿฆ Sharing it on social media
- ๐Ÿ“ Writing a blog post about your experience
- ๐Ÿ’ฐ [Sponsoring the project](https://github.com/sponsors/PicoBaz)

---

## ๐Ÿ™ Credits

- **Author**: [PicoBaz](https://github.com/PicoBaz)
- **Contributors**: [All Contributors](https://github.com/PicoBaz/gridview/graphs/contributors)
- Inspired by Yii2 GridView

---

**Made with โค๏ธ by [PicoBaz](https://github.com/PicoBaz)**

[โฌ† Back to Top](#-gridview)