thenandan / grids
Grids for Laravel 5+ frameworks
Installs: 144
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 0
Forks: 76
Type:laravel-library
Requires
- php: >=7.1.0
- illuminate/support: >=4.2
- laravelcollective/html: v6.*
- nayjest/builder: ~2
Requires (Dev)
- roave/security-advisories: dev-master
Suggests
- laravelcollective/html: Required to work with Laravel 5.X
- maatwebsite/excel: Required to work with Excel export component
- dev-master
- v3.2
- v3.0.x-dev
- v3.0.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- v0.9.12
- v0.9.11
- v0.9.10
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.13
- v0.7.12
- v0.7.11
- v0.7.10
- v0.7.9
- v0.7.8
- v0.7.7
- v0.7.6
- v0.7.5
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.1
- v0.5.0
- v0.4.10
- 0.4.9
- v0.4.8
- v0.4.7
- v0.4.6
- v0.4.5
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.21
- v0.3.20
- v0.3.19
- v0.3.18
- v0.3.17
- v0.3.16
- v0.3.15
- v0.3.14
- v0.3.13
- v0.3.12
- v0.3.11
- v0.3.10
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.0
This package is auto-updated.
Last update: 2025-02-14 19:14:56 UTC
README
Data Grids Framework for Laravel
This package is forked from Nayjest/Grids and is wrapper for the package, does not support (laravel < 5) and used bootstrap 4 by default.
Requirements
- Laravel >= 5+
- php >= 7.1
- bootstrap 4
- fontawesome 5
Installation
composer require thenandan/grids
Publishing Assets
php artisan vendor:publish --tag=public
Creating the Grid Class
php artisan make:grid CompanyGrid
This will generate the CompanyGrid class as below -
<?php namespace App\Grids; use Illuminate\Database\Eloquent\Model; use TheNandan\Grids\BaseGrid; class CompanyGrid extends BaseGrid { /** * Set root model for the grid query * * @return Model */ protected function setModel(): Model { // return new model instance } /** * Configure your grid * * @return void */ protected function configureGrid(): void { // Configure your grid column } }
Now we are going to configure our grid as below -
<?php namespace App\Grids; use Illuminate\Database\Eloquent\Model; use TheNandan\Grids\BaseGrid; class CompanyGrid extends BaseGrid { /** * Set root model for the grid query * * @return Model */ protected function setModel(): Model { return new Company(); } /** * Configure your grid * * @return void */ protected function configureGrid(): void { $this->grid->setCachingTime(0); $this->grid->addColumn('id', 'Id')->setSortable(); $this->grid->addColumn('unique_id', 'Unique ID')->setSortable()->setSearchFilter(); $this->grid->addColumn('name', 'Company Name')->setSortable()->setSearchFilter(); $this->grid->addColumn('created_at', 'Added On')->setCallback(function ($createdAt) { if (null === $createdAt || !$createdAt instanceof Carbon) { return '-'; } return Carbon::createFromTimestamp($createdAt->timestamp)->isoFormat('LLLL'); })->setDateFilter(); $this->grid->addColumn('edit_client', 'Edit')->setCallback(function ($val, $row) { return "<a href='#'><i class='fas fa-edit'></i></a>"; }); $this->grid->addColumn('delete_client', 'Delete')->setCallback(function ($val, $row) { return "<a href='#' class='text-danger'><i class='fas fa-trash'></i></a>"; }); } }
That's all, our grid is configured.
Rendering the Grid in UI
Create a blade(view) file (ex. company.blade.php) and include the grid in it. see below example -
@extends('layouts.app') @section('content') @include('grids::default') @endsection
Note
Make you to add the below in your main layout -
- In you header -
@yield('grid_css')
- Before closing the body tag -
@yield('grid_js')
Now create you route and return the company view. You will see a grid something similar to following.
Available Grid Methods
- setGridName($name) - Set the name of the grid
- setDefaultPageSize($number) - Set the default page size.
- setCachingTime($timeInMinute) - Set the caching time in minute.
- addColumn($column, $label = false, $relation = false) - Add a new column in grid.
- setRecordsPerPage(array $recordsPerPage) - Set records perPage dropdown list.
Available nested column methods
- setSortable() - When used column becomes sortable
- setCallback($function) - Can be used to customize the value of the cell
- shorten(int $noOfChar = 20) - Can be used to limit the no. of character in the grid cell, When used below methods become available
- setTitle() - Set the cell original value in html title attribute
- setToolTip($isHtml = false) - Set the cell original value in tooltip
- setPopover($isHtml = false, $title = null) - Set the cell original value in a popover, Here $title variable can be used to set the title of popover
- setLink($link, $name) - Can be used to set a link
- setSearchFilter($operator = TheNandanGrid::OPERATOR_LIKE) - Can be used to make the column searchable
- More methods are coming soon -
License
© 2020—2020 Keshari Nandan
License: Proprietary