GithubHelp home page GithubHelp logo

brucewu16899 / lvlgrid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marcosrjjunior/lvlgrid

0.0 2.0 0.0 10 KB

:sparkles: Grid helper to your Laravel application. Filter, order and pagination ajax

HTML 69.26% PHP 30.74%

lvlgrid's Introduction

lvlGrid

lvlgrid

Documentation


Dependencies

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.js"></script>

Installation

First, pull in the package through Composer.

composer require mrjj/lvlgrid

And then include the service provider within app/config/app.php.

'providers' => [
    Mrjj\LvlGrid\LvlGridServiceProvider::class
];

Getting started

First, create add a route to grid method

Route::get('countries/grid', '....Controller@grid');

Use a trait and add a required informations in your controller

use Mrjj\LvlGrid\LvlGrid;

class ..Controller extends Controller
{
    use LvlGrid

    protected $gridModel = \App\Models\Country::class;

    protected $threshold = 30;  
    ...
}

Finally, add this @includes(lvlgrid::...) , lvlgrid component and fill your infos

@extend('default')

@section('scripts')

    @include('lvlgrid::scripts')

@stop

@section('content')
    <h3>lvlGrid</h3>

    @include('lvlgrid::grid')  

    <div id="lvlgrid">

        <lvlgrid
            :data="items"
            :columns="[{
                'key': 'name',
                'name': 'Name'
            },{
                'key': 'monetary',
                'name': 'Monetary unit'
            }]"
            :routes="{
                function: '/countries/grid',
                edit: {
                    column: 'id',
                    name: '/countries/:column/edit'
                },
                delete: {
                    column: 'id',
                    name: '/countries/:column/delete'
                }
            }">
        </lvlgrid>

    </div>  
    ..

Get Data

Add a gridData() method if you want to customize your query

public function gridData()
{
    return DB::table('users')
            ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
}

@return \Illuminate\Database\Query\Builder

Transformer

To transform your data you need add a gridTransformer() method and modify what you want

public function gridTransformer($data)
{
    foreach($data['items'] as $_grid) {
        $_grid->status = trans('form.status.'.$_grid->status);
    }
 }

In this example I'm changing the status for a friendly name like 'Active' and 'Inactive'

If you need to modify the views, you can run:

php artisan vendor:publish --provider="Mrjj\LvlGrid\LvlGridServiceProvider"

The package views will now be located in the app/resources/views/vendor/mrjj/lvlgrid

lvlgrid's People

Contributors

marcosrjjunior avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.