2017 © Pedro Peláez
 

library grids

A Datagrid widget for laravel 5. It easily generate datatables from your entities.

image

sygmaa/grids

A Datagrid widget for laravel 5. It easily generate datatables from your entities.

  • Friday, April 15, 2016
  • by sygmaa
  • Repository
  • 2 Watchers
  • 9 Stars
  • 189 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 4 % Grown

The README.md

Grids

Grids is a datagrid widget for laravel 5. It easily generate datatables from your entities. The generated HTML use Twitter Bootstrap, but you can override templates., (*1)

Comming soon

  • A demo with more examples
  • CSV/Exel export
  • Possibility to extend the plugin, and add custom fields
  • Styling fields
  • And more...

Install

First, add this in your composer.json, (*2)

  "require": {
    "sygmaa/grids": "dev-master"
  }

Then, add a new Service provider in your config/app.php :, (*3)

'Sygmaa\Grids\GridsServiceProvider',, (*4)

And for the Facade :, (*5)

'Grids' => 'Sygmaa\Grids\GridsFacade',, (*6)

After, if you want override views or languages, you can run this command :, (*7)

php artisan vendor:publish, (*8)

Then, you must add these lines in your template :, (*9)

    {!! Grids::head() !!}
    {!! Grids::styles() !!}
    {!! Grids::scripts() !!}

Simple example

In your controller :, (*10)

$grid = Grids::make(new Model())
    // Pagination; 15 is the number of results to show by page
    ->paginate(15) 
    // Show a reset button to clear filters (In the filter form)
    ->reset() 
    // You can add a condition...
    ->where('field', '<', 'content') 
    // ...Many conditions
    ->where('field', 'content') 
    // Where In SQL Statement is supported
    ->whereIn('field', ['content1', 'content2']) 
    // Order by SQL Statement is supported
    ->orderBy('field', 'ASC') 
    // Add a new field (name, Label)
    ->addField(Grids::text('id', 'ID')
        // Define the primary key (needed)
        ->setPrimary() 
        // The field will be hidden
        ->setVisible(false) 
    )
    // You can create a custom field with a callback
    ->addField(Grids::custom('custom', 'custom', function($row){ 
      // You can access to the data of the actual row
      return $row->name; 
    })
    ->addField(Grids::text('name', 'Name')
        // An order by on this field will be available
        ->setSortable()
        // We can search keywords in an input
        ->setFilterable()
    )
    // Eloquent OneToMany/OneToOne relation
    // entities.name -> "entities" is your association method in your model ( entities() )
    // "name" is th name of the field in the associated model
    ->addField(Grids::oneRelation('entities.name', 'Label of entity', 'App\Models\EntityName')
         // You can filter the relation field
        ->setFilterable() 
    )
    // Eloquent ManyToMany relation
    // entity.name -> "entity" is your association method in your model ( entity() ), like oneRelation 
    // "name" is th name of the field in the associated model, like oneRelation
    // The result is a list (separated by comas)
    ->addField(Grids::manyRelation('entity.name', 'Label of entity', 'App\Models\EntityName') 
        ->setFilterable()
    )
    // Date field
    ->addField(Grids::date('updated_at', 'Dernière modification', 'd/m/Y H:i:s')
        ->setSortable()
        ->setFilterable() // You will have a bootstrap calendar to select period
    )
    // Add a mass action (For example : to delete entries)
    ->addAction(Grids::massAction("Delete", URL::route('model.delete')))
    // Add a single action at the end of the row : you can for example return a button
    ->addAction(Grids::action("Edit", function($label, $row){
        $url = URL::route('model.edit', ['id' => $row->id]);
        return '<a class="btn btn-primary" href="'. $url .'">'. $label .'</a>';
    })); // Add 

And the template :, (*11)



{!! $grid->renderFilters() !!}

License

Grids in under a MIT License., (*12)

The Versions

15/04 2016

dev-master

9999999-dev https://github.com/sygmaa/grids

A Datagrid widget for laravel 5. It easily generate datatables from your entities.

  Sources   Download

MIT

The Requires

 

laravel 5 datagrid datatable tables grids sygmaa table laravel datagrid laravel 5 laravel 5 datagrid grid laravel