All Projects → aginev → Datagrid

aginev / Datagrid

Licence: mit
Datagrid for Laravel v5

Projects that are alternatives of or similar to Datagrid

Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-11.36%)
Mutual labels:  laravel, composer, filter
Sieve
⚗️ Clean & extensible Sorting, Filtering, and Pagination for ASP.NET Core
Stars: ✭ 560 (+1172.73%)
Mutual labels:  filter, pagination
Ip Location Zh
获取 IP 地址的真实地理位置
Stars: ✭ 556 (+1163.64%)
Mutual labels:  laravel, composer
Sleepingowladmin
🦉 Administrative interface builder for Laravel (Laravel admin)
Stars: ✭ 671 (+1425%)
Mutual labels:  laravel, composer
Laravel Kit
A desktop Laravel admin panel app
Stars: ✭ 440 (+900%)
Mutual labels:  laravel, composer
Laravel React
Laravel 8 and React 17 boilerplate
Stars: ✭ 472 (+972.73%)
Mutual labels:  laravel, composer
Tables
Bulma themed, VueJS powered Datatable with server-side loading and JSON template setup
Stars: ✭ 575 (+1206.82%)
Mutual labels:  laravel, pagination
Docker Laravel
🐳 Build a simple laravel development environment with docker-compose.
Stars: ✭ 415 (+843.18%)
Mutual labels:  laravel, composer
Aliyun Sts
基于阿里云openapi系列接口中STS最新版本的SDK进行封装的composer package,解耦其他产品SDK,各个产品SDK功能使用组件化加载,减少代码臃肿。
Stars: ✭ 19 (-56.82%)
Mutual labels:  laravel, composer
Eloquent Filter
This simple package helps you filter Eloquent data using query filters.
Stars: ✭ 24 (-45.45%)
Mutual labels:  laravel, filter
Easyhttp
A Laravel HTTP-client to make HTTP request easier and log requests and responses
Stars: ✭ 20 (-54.55%)
Mutual labels:  laravel, composer
Performance
⏱ PHP performance tool analyser your script on time, memory usage and db query. Support Laravel and Composer for web, web console and command line interfaces.
Stars: ✭ 429 (+875%)
Mutual labels:  laravel, composer
Laravel Server Monitor
Server Monitoring Command for Laravel Applications
Stars: ✭ 424 (+863.64%)
Mutual labels:  laravel, composer
Laravel Vue Pagination
A Vue.js pagination component for Laravel paginators that works with Bootstrap
Stars: ✭ 541 (+1129.55%)
Mutual labels:  laravel, pagination
Vue Datasource
A vue.js component to create dynamic tables
Stars: ✭ 420 (+854.55%)
Mutual labels:  laravel, pagination
Hookphp
HookPHP基于C扩展搭建内置AI编程的架构系统-支持微服务部署|热插拔业务组件-集成业务模型|权限模型|UI组件库|多模板|多平台|多域名|多终端|多语言-含常驻内存|前后分离|API平台|LUA QQ群:679116380
Stars: ✭ 575 (+1206.82%)
Mutual labels:  laravel, composer
Laravel Wallet
Easy work with virtual wallet
Stars: ✭ 401 (+811.36%)
Mutual labels:  laravel, composer
Pusher Http Laravel
[DEPRECATED] A Pusher Channels bridge for Laravel
Stars: ✭ 410 (+831.82%)
Mutual labels:  laravel, composer
Package Skeleton
📦 My base for PHP packages.
Stars: ✭ 6 (-86.36%)
Mutual labels:  laravel, composer
Nem Php
NEM Blockchain NIS API Wrapper and Software Development Kit for PHP
Stars: ✭ 32 (-27.27%)
Mutual labels:  laravel, composer

Datagrid For Laravel 5+

Package that easily converts collection of models to a datagrid table. The main goal of the package is to build for you a table with sorting and filters per column. You are defining the grid structure in your controller, pass the datagrid to the view and show it there. This will give you a really clean views, just a single line to show the table + filters + sorting + pagination. Keep in mind that filtering and sorting the data is up to you!

Features

  • Composer installable
  • PSR4 autoloading
  • Has filters row
  • Has columns sort order
  • Easily can add action column with edit/delete/whatever links
  • Ability to modify cell data via closure function
  • Bootstrap friendly
  • Columns has data attributes based on a column data key

Requires

Build to be used with Laravel only!

Installation

Require package at your composer.json file like so

{
    "require": {
        "aginev/datagrid": "2.0.*"
    }
}

Tell composer to update your dependencies

composer update

Or in terminal

composer require aginev/datagrid:1.0.*

HOWTO

Let's consider that we have users and user roles (roles) table at our system.

Users table

id: primary key

role_id: foreign key to roles table primary key

email: user email added used as username

first_name: user first name

last_name: user last name

password: hashed password

created_at: when it's created

updated_at: when is the latest update

Roles Table

id: primary key

title: Role title e.g. Administrators Access

created_at: when it's created

updated_at: when is the latest update

We need a table with all the users data, their roles, edit and delete links at the last column at the table, filters and sort links at the very top, pagination at the very bottom.

<?php

// Grap all the users with their roles
// NB!!! At the next line you are responsible for data filtration and sorting!
$users = User::with('role')->paginate(25);

// Create Datagrid instance
// You need to pass the users and the URL query params that the package is using
$grid = new \Datagrid($users, Request::get('f', []));

// Or if you do not want to use the alias
//$grid = new \Aginev\Datagrid\Datagrid($users, Request::get('f', []));

// Then we are starting to define columns
$grid
	->setColumn('first_name', 'First Name', [
		// Will be sortable column
		'sortable'    => true,
		// Will have filter
		'has_filters' => true
	])
	->setColumn('email', 'Email', [
		'sortable'    => true,
		'has_filters' => true,
		// Wrapper closure will accept two params
		// $value is the actual cell value
		// $row are the all values for this row
		'wrapper'     => function ($value, $row) {
			return '<a href="mailto:' . $value . '">' . $value . '</a>';
		}
	])
	->setColumn('role_id', 'Role', [
		// If you want to have role_id in the URL query string but you need to show role.name as value (dot notation for the user/role relation)
		'refers_to'   => 'role.name',
		'sortable'    => true,
		'has_filters' => true,
		// Pass array of data to the filter. It will generate select field.
		'filters'     => Role::all()->lists('title', 'id'),
		// Define HTML attributes for this column
		'attributes'  => [
            'class'         => 'custom-class-here',
            'data-custom'   => 'custom-data-attribute-value',
        ],
	])
	->setColumn('created_at', 'Created', [
		'sortable'    => true,
		'has_filters' => true,
		'wrapper'     => function ($value, $row) {
			// The value here is still Carbon instance, so you can format it using the Carbon methods
			return $value;
		}
	])
	->setColumn('updated_at', 'Updated', [
		'sortable'    => true,
		'has_filters' => true
	])
	// Setup action column
	->setActionColumn([
		'wrapper' => function ($value, $row) {
			return '<a href="' . action('[email protected]', $row->id) . '" title="Edit" class="btn btn-xs"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
					<a href="' . action('[email protected]', $row->id) . '" title="Delete" data-method="DELETE" class="btn btn-xs text-danger" data-confirm="Are you sure?"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>';
		}
	]);

// Finally pass the grid object to the view
return view('grid', ['grid' => $grid]);

Lets show the grid in the view. grid-table param is not required and it's the id of the table.

...
{!! $grid->show('grid-table') !!}
...

Modifying Default View

php artisan vendor:publish --provider="Aginev\Datagrid\DatagridServiceProvider" --tag="views"

This will copy the view to resources/views/vendor/datagrid/datagrid.blade.php. Editing this file you will be able to modify the grid view as you like with no chance to loose your changes.

Modifying Config

php artisan vendor:publish --provider="Aginev\Datagrid\DatagridServiceProvider" --tag="config"

This will copy the config to config/datagrid.php.

License

MIT - http://opensource.org/licenses/MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].