Download the PHP package apphp/laravel-datagrid without Composer
On this page you can find all versions of the php package apphp/laravel-datagrid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download apphp/laravel-datagrid
More information about apphp/laravel-datagrid
Files in apphp/laravel-datagrid
Package laravel-datagrid
Short Description DataGrid helpers for easy creating CRUD in Laravel Framework Applications
License MIT
Homepage https://apphp.com
Informations about the package laravel-datagrid
DataGrid helpers for Laravel Framework Applications
This package helps to create DataGrid (CRUD) pages for Laravel 6+ framework applications.
Requirements
- PHP >=7.1
- Laravel 6+
- Bootstrap 3+
License
This project is released under the MIT License.
Copyright © 2020 ApPHP.
Installation
Begin by pulling in the package through Composer.
Next, make sure you connected Bootstrap. You may either pull in the Bootstrap's CSS within your HTML or layout file, or write your own CSS classes based on them.
If you need to modify the datagrid files, you can run:
Usage in Controllers
1. Import classes
2. Define filters and filter field types
Following filter field types are available
Type | Description |
---|---|
string |
Any type of strings |
integer or int |
Numeric integer field (HTML type="number" attribute is used) |
set |
Set of values (array) |
date |
The datetime fields |
Each filter field can include following attributes:
Attribute | Type | Description |
---|---|---|
title |
String | Specifies a title, that will be shown in the label of filter field |
type |
String | Specifies a type of the filter field (see above) |
compareType |
String | Specifies which type of comparison will be used: ex.: '=', '%like%', '!=' etc. |
source |
Array | Specifies the source (array) to 'set' fields |
validation |
Array | Specifies validation rules (array). Possible options: ['minLength'=>2, 'maxLength'=>10, 'min'=>2, 'max'=>100] |
relation |
String | Specifies the relation between 2 models (One-to-One, One-to-Many), ex.: search in posts for users - relation="posts" |
relationXref |
String | Specifies the relation between 2 models (Many-to-Many), ex.: search in roles for users - relation="roles" |
htmlOptions |
Array | Specifies any possible HTML attribute for the field |
disabled |
Boolean | Specifies whether the field is disabled or not (default - not) |
3. Handle filters and prepare SQL builder
4. Sorting
5. Pagination
6. Rendering view
Usage in View files
Configuration
To change default settings and enable some extra features you can export the config file:
Localization
To change or add new translation files you can export the language files:
Customize Views
To change HTML template of the datagrid or use your own, publish view file and customize it to suit your needs.
Now you should have a datagrid.php file in the config folder of your application. If you need to force to re-publish the config file to use --force
.
Testing
To rum unit testing simply do following:
or your may add additional section to your composer.json file:
and then rum unit following command:
and so on...
Examples
Controller code (full example)
Sorting
If you use some kind of packages for column sorting, like kyslik/column-sortable
, you have to change usage of Model to following:
Without sorting
With column sorting
Table content rendering
You have 2 way to render table content. The first is to write creating table manually in view file. Look on example below:
The second way is to use GridView
helper. Look on example below:
You may also use a callback
attribute to customize values of the specific field. This attribute accepts a function, link to function or a closure.
Below you may find few examples to get a feel:
Show specific badge if user has verified
Show a list of user roles, get array of roles via $roles
parameter
Show user's avatar with a link to edit
Collapsed filter
Expanded filter
Pagination
All versions of laravel-datagrid with dependencies
illuminate/support Version ~5.0|^6.0|^7.0|^8.0|^9.0|^10
jenssegers/agent Version ^2.6